Finding the smallest number whose digits sum to N
The program should look more like this:
public static void main(String[] args) {
    int m = askInt(&quot;Enter the value of M: &quot;, 100, 10000),
        n = askInt(&quot;Enter the value of N: &quot;, 1, 100);
    long solution = findSolution(m, n);
    System.out.println(&quot;Minimum number is: &quot; + solution);
    System.out.println(&quot;Total number of digits: &quot; + numberOfDigits(solution));
}

Notable differences:

Your program isn't object-oriented anyway, so there's no point in instantiating a and calling input() as an instance method.  (Furthermore, it's weird that input(), which is an instance method, stores its results in static variables instead of instance variables.)
There is a lot of repetition within input().  A general-purpose integer-prompting routine, used for both M and N, would be better.
m, n, and ndigit should not be static variables, as that makes them essentially global variables.  Any function in the class can alter their values as a side-effect, making your code harder to analyze — you have to read all of the code to understand any of it.
The solution needs to be a long, in case N is large. As @OleTange pointed out, if N is 99, then the solution must be at least 99999999999, which won't fit in an int. Note that brute-force enumeration is a very poor strategy for such large numbers.


Here's how I would write askInt():
static int askInt(String prompt, int min, int max) {
    int result;
    System.out.println(prompt);
    while ((result = sc.nextInt()) &lt; min || result &gt; max) {
        System.out.println(&quot;Invalid input, enter again: &quot;);
    }
    return result;
}

Note that it returns a value to the caller, rather than setting some variable as a side-effect.

Assuming that we stick with your brute-force algorithm (and indeed there is a much faster way), these functions could be improved:
static int sumOfDigits(long num) {
    int sum = 0;
    while (num &gt; 0) {
        sum += num % 10;
        num /= 10;
    }
    return sum;
}

static int numberOfDigits(long num) {
    return (int)Math.log10(num) + 1;
}

Arithmetic is preferable to converting numbers to strings and back.  Keep in mind that the stringification process itself involves similar arithmetic operations, and therefore must be slower than arithmetic.  Dealing with strings also incurs a cost for allocating memory for them.
I've chosen num as the parameter names to avoid confusion with the N in the problem statement.

As for the solution search itself, there are two bugs:

The problem calls for the solution to be strictly greater than M.
The problem does not state that the solution should be capped at 10000.  (For example, given M = 10000 and N = 2, the solution should be 10001.)


public static long findSolution(int m, int n) {
    for (long i = m + 1; ; i++) {
        if (sumOfDigits(i) == n) {
            return i;
        }
    }
}