第二题AC40% 帮忙看下哪里出错了

public static String solution(long n, int m) {
        String str = String.valueOf(n);
        if (m >= str.length()) {
            return null;
        }
        for (int i = 0; i < str.length() - 1; i++) {
            if (str.charAt(i) < str.charAt(i+1)) {
                str = str.replaceFirst(String.valueOf(str.charAt(i)), "");
                m--;
                i = -1;
            }
            if (m <= 0) {
                break;
            }
        }
        String result ="";
        if (m > 0) {

            char[] temp = str.toCharArray();
            for (int i = 0; i < temp.length - m; i++) {
                result += temp[i];
            }
        }else {
            result = str;
        }
        return result;
    }