private long rec(int i, int current) {
        if (DP[i][current] != -1)
            return DP[i][current];

        if (i >= M.length()) {
            return 1;
        }
        Integer x = M.charAt(i) - '0';
        int next = 10 * current + x;

        long res = 0;

        if (next > 0 && next <= N) {
            res = rec(i + 1, next)%MOD;
        }

        if (i > 0 && x != 0 && x <= N) {
            res = (res + rec(i + 1, x))%MOD;
        }

        return DP[i][current] = res%MOD;
    }