import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.TreeSet;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.util.Comparator;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Vadim
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ecr43C solver = new ecr43C();
        solver.solve(1, in, out);
        out.close();
    }

    static class ecr43C {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int n = in.ni();
            Seg[] a = new Seg[n];
            for (int i = 0; i < n; i++) {
                a[i] = new Seg(i + 1, in.ni(), in.ni());
            }
            Arrays.sort(a, Comparator.comparingInt(o -> o.r));
            TreeSet<Seg> tree = new TreeSet<>(new Comparator<Seg>() {

                public int compare(Seg o1, Seg o2) {
                    return Integer.compare(o2.l, o1.l);
                }
            });
            for (Seg seg : a) {
                if (!tree.isEmpty()) {
                    Seg lb = tree.first();
                    if (lb.l >= seg.l) {
                        out.printf("%d %d%n", seg.id, lb.id);
                        return;
                    }
                }
                tree.add(seg);
            }
            out.println("-1 -1");
        }

        class Seg {
            int id;
            int l;
            int r;

            public Seg(int id, int l, int r) {
                this.id = id;
                this.l = l;
                this.r = r;
            }

        }

    }

    static class FastScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public FastScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String ns() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public int ni() {
            return Integer.parseInt(ns());
        }

    }
}


import java.util.*;
import java.io.*;

public class C {
    static void go() {
        int n = in.nextInt();
        int[][] a = new int[n][3];
        for (int i = 0; i < n; i++) {
            a[i][0] = in.nextInt();
            a[i][1] = in.nextInt();
            a[i][2] = i + 1;
        }
        Arrays.sort(a, (x, y) -> (x[0] == y[0] ? x[1] - y[1] : x[0] - y[0]));
        int[] pre = a[0];
        for (int i = 1; i < n; i++) {
            if (a[i][1] <= pre[1]) {
                out.println(pre[2] + " " + a[i][2]);
                return;
            }
            pre = a[i];
        }
        out.println("-1 -1");
    }

    static InputReader in;
    static PrintWriter out;

    public static void main(String[] args) {
        in = new InputReader(System.in);
        out = new PrintWriter(System.out);

        go();

        out.close();
    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int[] nextIntArray(int len) {
            int[] ret = new int[len];
            for (int i = 0; i < len; i++)
                ret[i] = nextInt();
            return ret;
        }

        public long[] nextLongArray(int len) {
            long[] ret = new long[len];
            for (int i = 0; i < len; i++)
                ret[i] = nextLong();
            return ret;
        }

        public int nextInt() {
            return (int) nextLong();
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public String nextLine() {
            StringBuilder sb = new StringBuilder(1024);
            int c = read();
            while (!(c == '\n' || c == '\r' || c == -1)) {
                sb.append((char) c);
                c = read();
            }
            return sb.toString();
        }

        public char nextChar() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            return (char) c;
        }

        public String nextString() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder sb = new StringBuilder(1024);
            do {
                sb.append((char) c);
                c = read();
            } while (!isSpaceChar(c));
            return sb.toString();
        }

        public char[] nextCharArray(int n) {
            char[] ca = new char[n];
            for (int i = 0; i < n; i++) {
                int c = read();
                while (isSpaceChar(c))
                    c = read();
                ca[i] = (char) c;
            }
            return ca;
        }

        public static boolean isSpaceChar(int c) {
            switch (c) {
                case -1:
                case ' ':
                case '\n':
                case '\r':
                case '\t':
                    return true;
                default:
                    return false;
            }
        }
    }
}


import java.util.*;
import java.io.*;

public class C {
    static void go() {
        int n = in.nextInt();
        int[][] a = new int[n][3];
        for (int i = 0; i < n; i++) {
            a[i][0] = in.nextInt();
            a[i][1] = in.nextInt();
            a[i][2] = i + 1;
        }
        Arrays.sort(a, (x, y) -> (x[0] == y[0] ? y[1] - x[1] : x[0] - y[0]));
        int[] pre = a[0];
        for (int i = 1; i < n; i++) {
            if (a[i][1] <= pre[1]) {
                out.println(a[i][2] + " " + pre[2]);
                return;
            }
            pre = a[i];
        }
        out.println("-1 -1");
    }

    static InputReader in;
    static PrintWriter out;

    public static void main(String[] args) {
        in = new InputReader(System.in);
        out = new PrintWriter(System.out);

        go();

        out.close();
    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int[] nextIntArray(int len) {
            int[] ret = new int[len];
            for (int i = 0; i < len; i++)
                ret[i] = nextInt();
            return ret;
        }

        public long[] nextLongArray(int len) {
            long[] ret = new long[len];
            for (int i = 0; i < len; i++)
                ret[i] = nextLong();
            return ret;
        }

        public int nextInt() {
            return (int) nextLong();
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public String nextLine() {
            StringBuilder sb = new StringBuilder(1024);
            int c = read();
            while (!(c == '\n' || c == '\r' || c == -1)) {
                sb.append((char) c);
                c = read();
            }
            return sb.toString();
        }

        public char nextChar() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            return (char) c;
        }

        public String nextString() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder sb = new StringBuilder(1024);
            do {
                sb.append((char) c);
                c = read();
            } while (!isSpaceChar(c));
            return sb.toString();
        }

        public char[] nextCharArray(int n) {
            char[] ca = new char[n];
            for (int i = 0; i < n; i++) {
                int c = read();
                while (isSpaceChar(c))
                    c = read();
                ca[i] = (char) c;
            }
            return ca;
        }

        public static boolean isSpaceChar(int c) {
            switch (c) {
                case -1:
                case ' ':
                case '\n':
                case '\r':
                case '\t':
                    return true;
                default:
                    return false;
            }
        }
    }
}


import java.util.*;
import java.io.*;

public class C {
    static void go() {
        int n = in.nextInt();
        int[][] a = new int[n][3];
        for (int i = 0; i < n; i++) {
            a[i][0] = in.nextInt();
            a[i][1] = in.nextInt();
            a[i][2] = i + 1;
        }
        Arrays.sort(a, (x, y) -> (x[0] == y[0] ? x[1] - y[1] : x[0] - y[0]));
        int[] pre = a[0];
        for (int i = 1; i < n; i++) {
            if (a[i][1] <= pre[1]) {
                out.println(a[i][2] + " " + pre[2]);
                return;
            }
            pre = a[i];
        }
        out.println("-1 -1");
    }

    static InputReader in;
    static PrintWriter out;

    public static void main(String[] args) {
        in = new InputReader(System.in);
        out = new PrintWriter(System.out);

        go();

        out.close();
    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int[] nextIntArray(int len) {
            int[] ret = new int[len];
            for (int i = 0; i < len; i++)
                ret[i] = nextInt();
            return ret;
        }

        public long[] nextLongArray(int len) {
            long[] ret = new long[len];
            for (int i = 0; i < len; i++)
                ret[i] = nextLong();
            return ret;
        }

        public int nextInt() {
            return (int) nextLong();
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public String nextLine() {
            StringBuilder sb = new StringBuilder(1024);
            int c = read();
            while (!(c == '\n' || c == '\r' || c == -1)) {
                sb.append((char) c);
                c = read();
            }
            return sb.toString();
        }

        public char nextChar() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            return (char) c;
        }

        public String nextString() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder sb = new StringBuilder(1024);
            do {
                sb.append((char) c);
                c = read();
            } while (!isSpaceChar(c));
            return sb.toString();
        }

        public char[] nextCharArray(int n) {
            char[] ca = new char[n];
            for (int i = 0; i < n; i++) {
                int c = read();
                while (isSpaceChar(c))
                    c = read();
                ca[i] = (char) c;
            }
            return ca;
        }

        public static boolean isSpaceChar(int c) {
            switch (c) {
                case -1:
                case ' ':
                case '\n':
                case '\r':
                case '\t':
                    return true;
                default:
                    return false;
            }
        }
    }
}


import java.util.*;
import java.io.*;

public class C {
    static void go() {
        int n = in.nextInt();
        int[][] a = new int[n][3];
        for (int i = 0; i < n; i++) {
            a[i][0] = in.nextInt();
            a[i][1] = in.nextInt();
            a[i][2] = i + 1;
        }
        Arrays.sort(a, (x, y) -> (x[0] == y[0] ? x[1] - y[1] : x[0] - y[0]));
        int[] pre = a[0];
        for (int i = 1; i < n; i++) {
            if (pre[0] >= a[i][0]) {
                out.println(pre[2] + " " + a[i][2]);
                return;
            }
            pre = a[i];
        }
        out.println("-1 -1");
    }

    static InputReader in;
    static PrintWriter out;

    public static void main(String[] args) {
        in = new InputReader(System.in);
        out = new PrintWriter(System.out);

        go();

        out.close();
    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int[] nextIntArray(int len) {
            int[] ret = new int[len];
            for (int i = 0; i < len; i++)
                ret[i] = nextInt();
            return ret;
        }

        public long[] nextLongArray(int len) {
            long[] ret = new long[len];
            for (int i = 0; i < len; i++)
                ret[i] = nextLong();
            return ret;
        }

        public int nextInt() {
            return (int) nextLong();
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public String nextLine() {
            StringBuilder sb = new StringBuilder(1024);
            int c = read();
            while (!(c == '\n' || c == '\r' || c == -1)) {
                sb.append((char) c);
                c = read();
            }
            return sb.toString();
        }

        public char nextChar() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            return (char) c;
        }

        public String nextString() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder sb = new StringBuilder(1024);
            do {
                sb.append((char) c);
                c = read();
            } while (!isSpaceChar(c));
            return sb.toString();
        }

        public char[] nextCharArray(int n) {
            char[] ca = new char[n];
            for (int i = 0; i < n; i++) {
                int c = read();
                while (isSpaceChar(c))
                    c = read();
                ca[i] = (char) c;
            }
            return ca;
        }

        public static boolean isSpaceChar(int c) {
            switch (c) {
                case -1:
                case ' ':
                case '\n':
                case '\r':
                case '\t':
                    return true;
                default:
                    return false;
            }
        }
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public final class C {

    private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    private static Segment[] segments;

    public static final void main(final String[] args) throws IOException {
        final int n = Integer.parseInt(br.readLine().trim());
        segments = new Segment[n];
        for(int i = 0 ; i < n ; ++i) {
            final String[] splitter = br.readLine().split(" ");
            final int from = Integer.parseInt(splitter[0]);
            final int to = Integer.parseInt(splitter[1]);
            segments[i] = new Segment(from, to, i);
        }

        Arrays.sort(segments);

        for(int i = 1 ; i < segments.length ; ++i) {
            if(segments[i].contains(segments[i - 1])) {
                System.out.println(segments[i - 1].index + " " + segments[i].index);
                return;
            }

            if(segments[i - 1].contains(segments[i])) {
                System.out.println(segments[i].index + " " + segments[i - 1].index);
                return;
            }
        }

        System.out.println("-1 -1");
    }

    private static final class Segment implements Comparable<Segment> {

        public final int from;
        public final int to;
        public final int index;

        public Segment(final int from, final int to, final int index) {
            this.from = from;
            this.to = to;
            this.index = index + 1;
        }

        public boolean contains(final Segment segment) {
            return segment.from >= from && segment.to <= to;
        }

        @Override
        public int compareTo(final Segment segment) {
            if(from != segment.from) {
                return from - segment.from;
            } else {
                return segment.to - to;
            }
        }
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public final class C {

    private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    private static Segment[] segments;

    public static final void main(final String[] args) throws IOException {
        final int n = Integer.parseInt(br.readLine().trim());
        segments = new Segment[n];
        for(int i = 0 ; i < n ; ++i) {
            final String[] splitter = br.readLine().split(" ");
            final int from = Integer.parseInt(splitter[0]);
            final int to = Integer.parseInt(splitter[1]);
            segments[i] = new Segment(from, to);
        }

        Arrays.sort(segments);

        int i = 0;
        int j = 1;

        while(j < n) {
            if(segments[i].contains(segments[j])) {
                System.out.println((j + 1) + " " + (i + 1));
                return;
            }

            if(segments[j].contains(segments[i])) {
                System.out.println((i + 1) + " " + (j + 1));
                return;
            }
        }

        System.out.println("-1 -1");
    }

    private static final class Segment implements Comparable<Segment> {

        public final int from;
        public final int to;

        public Segment(final int from, final int to) {
            this.from = from;
            this.to = to;
        }

        public boolean contains(final Segment segment) {
            return segment.from >= from && segment.to <= to;
        }

        @Override
        public int compareTo(final Segment segment) {
            if(from != segment.from) {
                return from - segment.from;
            } else {
                return to - segment.to;
            }
        }
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public final class C {

    private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    private static Segment[] segments;

    public static final void main(final String[] args) throws IOException {
        final int n = Integer.parseInt(br.readLine().trim());
        segments = new Segment[n];
        for(int i = 0 ; i < n ; ++i) {
            final String[] splitter = br.readLine().split(" ");
            final int from = Integer.parseInt(splitter[0]);
            final int to = Integer.parseInt(splitter[1]);
            segments[i] = new Segment(from, to);
        }

        Arrays.sort(segments);

        int i = 0;
        int j = 1;

        while(j < n) {
            if(segments[i].contains(segments[j])) {
                System.out.println((j + 1) + " " + (i + 1));
                return;
            }

            if(segments[j].contains(segments[i])) {
                System.out.println((i + 1) + " " + (j + 1));
                return;
            }

            if(segments[j].from > segments[i].to) {
                ++i;
            } else {
                ++j;
            }
        }

        System.out.println("-1 -1");
    }

    private static final class Segment implements Comparable<Segment> {

        public final int from;
        public final int to;

        public Segment(final int from, final int to) {
            this.from = from;
            this.to = to;
        }

        public boolean contains(final Segment segment) {
            return segment.from >= from && segment.to <= to;
        }

        @Override
        public int compareTo(final Segment segment) {
            if(from != segment.from) {
                return from - segment.from;
            } else {
                return to - segment.to;
            }
        }
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public final class C {

    private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    private static Segment[] segments;

    public static final void main(final String[] args) throws IOException {
        final int n = Integer.parseInt(br.readLine().trim());
        segments = new Segment[n];
        for(int i = 0 ; i < n ; ++i) {
            final String[] splitter = br.readLine().split(" ");
            final int from = Integer.parseInt(splitter[0]);
            final int to = Integer.parseInt(splitter[1]);
            segments[i] = new Segment(from, to, i);
        }

        Arrays.sort(segments);

        int i = 0;
        int j = 1;

        while(j < n) {
            if(i == j) {
                ++j;
                continue;
            }

            if(segments[i].contains(segments[j])) {
                System.out.println(segments[j].index + " " + segments[i].index);
                return;
            }

            if(segments[j].contains(segments[i])) {
                System.out.println(segments[i].index + " " + segments[j].index);
                return;
            }

            if(segments[j].from > segments[i].to) {
                ++i;
            } else {
                ++j;
            }
        }

        System.out.println("-1 -1");
    }

    private static final class Segment implements Comparable<Segment> {

        public final int from;
        public final int to;
        public final int index;

        public Segment(final int from, final int to, final int index) {
            this.from = from;
            this.to = to;
            this.index = index + 1;
        }

        public boolean contains(final Segment segment) {
            return segment.from >= from && segment.to <= to;
        }

        @Override
        public int compareTo(final Segment segment) {
            if(from != segment.from) {
                return from - segment.from;
            } else {
                return to - segment.to;
            }
        }
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public final class C {

    private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    private static Segment[] segments;

    public static final void main(final String[] args) throws IOException {
        final int n = Integer.parseInt(br.readLine().trim());
        segments = new Segment[n];
        for(int i = 0 ; i < n ; ++i) {
            final String[] splitter = br.readLine().split(" ");
            final int from = Integer.parseInt(splitter[0]);
            final int to = Integer.parseInt(splitter[1]);
            segments[i] = new Segment(from, to, i);
        }

        Arrays.sort(segments);

        int i = 0;
        int j = 1;

        while(j < n) {
            if(segments[i].contains(segments[j])) {
                System.out.println(segments[j].index + " " + segments[i].index);
                return;
            }

            if(segments[j].contains(segments[i])) {
                System.out.println(segments[i].index + " " + segments[j].index);
                return;
            }

            if(segments[j].from > segments[i].to) {
                ++i;
            } else {
                ++j;
            }
        }

        System.out.println("-1 -1");
    }

    private static final class Segment implements Comparable<Segment> {

        public final int from;
        public final int to;
        public final int index;

        public Segment(final int from, final int to, final int index) {
            this.from = from;
            this.to = to;
            this.index = index + 1;
        }

        public boolean contains(final Segment segment) {
            return segment.from >= from && segment.to <= to;
        }

        @Override
        public int compareTo(final Segment segment) {
            if(from != segment.from) {
                return from - segment.from;
            } else {
                return to - segment.to;
            }
        }
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public final class C {

    private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    private static Segment[] segments;

    public static final void main(final String[] args) throws IOException {
        final int n = Integer.parseInt(br.readLine().trim());
        segments = new Segment[n];
        for(int i = 0 ; i < n ; ++i) {
            final String[] splitter = br.readLine().split(" ");
            final int from = Integer.parseInt(splitter[0]);
            final int to = Integer.parseInt(splitter[1]);
            segments[i] = new Segment(from, to);
        }

        Arrays.sort(segments);

        int i = 0;
        int j = 1;

        while(j < n) {
            if(segments[i].contains(segments[j]) || segments[j].contains(segments[i])) {
                System.out.println((i + 1) + " " + (j + 1));
                return;
            }
        }

        System.out.println("-1 -1");
    }

    private static final class Segment implements Comparable<Segment> {

        public final int from;
        public final int to;

        public Segment(final int from, final int to) {
            this.from = from;
            this.to = to;
        }

        public boolean contains(final Segment segment) {
            return segment.from >= from && segment.to <= to;
        }

        @Override
        public int compareTo(final Segment segment) {
            if(from != segment.from) {
                return from - segment.from;
            } else {
                return to - segment.to;
            }
        }
    }
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class vk18
{
    public static void main(String[] stp) throws Exception
    {
        Scanner scan = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        int n=Integer.parseInt(st.nextToken()),i;
        Pair pair[]=new Pair[n];
        for(i=0;i<n;i++)
        {
            st = new StringTokenizer(br.readLine());
            pair[i]=new Pair(Integer.parseInt(st.nextToken()),Integer.parseInt(st.nextToken()),i);
        }
        Arrays.sort(pair,new Pair.First().thenComparing(new Pair.Second()));
        for(i=1;i<n;i++)
        {
            if(pair[i-1].g >= pair[i].g && pair[i-1].g >= pair[i].d) { pw.println((pair[i-1].i +1)+" "+(pair[i].i+1)); pw.flush(); System.exit(0);}
        }
        pw.println("-1 -1");
        pw.flush();
    }
    static class Pair implements Comparable<Pair>
    {
        int d, g,i;

        public Pair(int d, int g,int i)
        {
            this.d = d;
            this.g = g;
            this.i = i;
        }

        @Override
        public int compareTo(Pair p) {
            return 1;
        }

        static class First implements Comparator<Pair>
        {
            public int compare(Pair q, Pair s)
            {
                return -Integer.compare(s.d, q.d);
            }
        }

        static class Second implements Comparator<Pair>
        {
            public int compare(Pair q, Pair s)
            {
                return -Integer.compare(q.g, s.g);
            }
        }
    }

}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class vk18
{
    public static void main(String[] stp) throws Exception
    {
        Scanner scan = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        int n=Integer.parseInt(st.nextToken()),i;
        Pair pair[]=new Pair[n];
        for(i=0;i<n;i++)
        {
            st = new StringTokenizer(br.readLine());
            pair[i]=new Pair(Integer.parseInt(st.nextToken()),Integer.parseInt(st.nextToken()),i);
        }
        Arrays.sort(pair,new Pair.First().thenComparing(new Pair.Second()));
        for(i=1;i<n;i++)
        {
            if(pair[i-1].g >= pair[i].g && pair[i-1].g >= pair[i].d) { pw.println((pair[i].i +1)+" "+(pair[i-1].i+1)); pw.flush(); System.exit(0);}
        }
        pw.println("-1 -1");
        pw.flush();
    }
    static class Pair implements Comparable<Pair>
    {
        int d, g,i;

        public Pair(int d, int g,int i)
        {
            this.d = d;
            this.g = g;
            this.i = i;
        }

        @Override
        public int compareTo(Pair p) {
            return 1;
        }

        static class First implements Comparator<Pair>
        {
            public int compare(Pair q, Pair s)
            {
                return -Integer.compare(s.d, q.d);
            }
        }

        static class Second implements Comparator<Pair>
        {
            public int compare(Pair q, Pair s)
            {
                return -Integer.compare(q.g, s.g);
            }
        }
    }
}


import java.util.*;
import java.io.*;
import java.math.*;
public class code5 {
	InputStream is;
	PrintWriter out;
	static long mod=pow(10,9)+7;
	int dx[]= {0,0,1,-1},dy[]={+1,-1,0,0};
	void solve()
	{
		int n=ni();
		Pair p[]=new Pair[n];
		for(int i=0;i<n;i++)
			p[i]=new Pair(ni(),ni(),i);
		Arrays.sort(p);
		long max=p[0].y,index=p[0].i;
		for(int i=1;i<n;i++)
		{
			if(p[i].y<=max)
			{
				System.out.println((p[i].i+1)+" "+(index+1));
				return;
			}
			if(p[i].y>max) {
				max=p[i].y;
				index=p[i].i;
			}
		}
		System.out.println(-1+" "+-1);

	}
	ArrayList<Integer>al [];
	void take(int n,int m)
	{
		al=new ArrayList[n];
		for(int i=0;i<n;i++)
			al[i]=new ArrayList<Integer>();
		for(int i=0;i<m;i++)
		{
			int x=ni()-1;
			int y=ni()-1;
			al[x].add(y);
			al[y].add(x);
		}
	}
	int arr[][];
	int small[];
	void pre(int n)
	{
		small=new int[n+1];
		for(int i=2;i*i<=n;i++)
		{
			for(int j=i;j*i<=n;j++)
			{
				if(small[i*j]==0)
					small[i*j]=i;
			}
		}
		for(int i=0;i<=n;i++)
		{
			if(small[i]==0)
				small[i]=i;
		}
	}
	public static int count(int x)
	{
		int num=0;
		while(x!=0)
		{
			x=x&(x-1);
			num++;
		}
		return num;
	}
	static long d, x, y;
	void extendedEuclid(long A, long B) {
	    if(B == 0) {
	        d = A;
	        x = 1;
	        y = 0;
	    }
	    else {
	        extendedEuclid(B, A%B);
	        long temp = x;
	        x = y;
	        y = temp - (A/B)*y;
	    }
	}
	long modInverse(long A,long M) //A and M are coprime
	{
	    extendedEuclid(A,M);
	    return (x%M+M)%M;    //x may be negative
	}
	public static void mergeSort(int[] arr, int l ,int r){
		if((r-l)>=1){
			int mid = (l+r)/2;
			mergeSort(arr,l,mid);
			mergeSort(arr,mid+1,r);
			merge(arr,l,r,mid);
		}
	}
	public static void merge(int arr[], int l, int r, int mid){
		int n1 = (mid-l+1), n2 = (r-mid);
		int left[] = new int[n1];
		int right[] = new int[n2];
		for(int i =0 ;i<n1;i++) left[i] = arr[l+i];
		for(int i =0 ;i<n2;i++) right[i] = arr[mid+1+i];
		int i =0, j =0, k = l;
		while(i<n1 && j<n2){
			if(left[i]>right[j]){
				arr[k++] = right[j++];
			}
			else{
				arr[k++] = left[i++];
			}
		}
		while(i<n1) arr[k++] = left[i++];
		while(j<n2) arr[k++] = right[j++];
	}
	public static void mergeSort(long[] arr, int l ,int r){
		if((r-l)>=1){
			int mid = (l+r)/2;
			mergeSort(arr,l,mid);
			mergeSort(arr,mid+1,r);
			merge(arr,l,r,mid);
		}
	}
	public static void merge(long arr[], int l, int r, int mid){
		int n1 = (mid-l+1), n2 = (r-mid);
		long left[] = new long[n1];
		long right[] = new long[n2];
		for(int i =0 ;i<n1;i++) left[i] = arr[l+i];
		for(int i =0 ;i<n2;i++) right[i] = arr[mid+1+i];
		int i =0, j =0, k = l;
		while(i<n1 && j<n2){
			if(left[i]>right[j]){
				arr[k++] = right[j++];
			}
			else{
				arr[k++] = left[i++];
			}
		}
		while(i<n1) arr[k++] = left[i++];
		while(j<n2) arr[k++] = right[j++];
	}
	 static class Pair implements Comparable<Pair>{

	      long x;
	      long y,k,i;
		Pair (long x,long y,long i){
			this.x=x;
			this.y=y;
			this.i=i;
		}

		public int compareTo(Pair o) {
			if(this.x!=o.x)
				return Long.compare(this.x,o.x);
			return  Long.compare(this.y,o.y);
		}
		public boolean equals(Object o) {
			if (o instanceof Pair) {
				Pair p = (Pair)o;
				return p.x == x && p.y == y;
			}
			return false;
		}
		public int hashCode() {
			return new Long(x).hashCode()*31 + new Long(y).hashCode() ;
		}

	        @Override
	        public String toString() {
	            return  "("+x + " " + y +" "+k+" "+i+" )";
	        }

	    }

	    public static boolean isPal(String s){
	        for(int i=0, j=s.length()-1;i<=j;i++,j--){
	                if(s.charAt(i)!=s.charAt(j)) return false;
	        }
	        return true;
	    }
	    public static String rev(String s){
			StringBuilder sb=new StringBuilder(s);
			sb.reverse();
			return sb.toString();
	    }

	    public static long gcd(long x,long y){
		if(x%y==0)
			return y;
		else
			return gcd(y,x%y);
	    }

	    public static int gcd(int x,int y){
	    	if(y==0)
	    		return x;
	    	return gcd(y,x%y);
	    }

	    public static long gcdExtended(long a,long b,long[] x){

	        if(a==0){
	            x[0]=0;
	            x[1]=1;
	            return b;
	        }
	        long[] y=new long[2];
	        long gcd=gcdExtended(b%a, a, y);

	        x[0]=y[1]-(b/a)*y[0];
	        x[1]=y[0];

	        return gcd;
	    }

	    public static int abs(int a,int b){
		return (int)Math.abs(a-b);
	    }

	    public static long abs(long a,long b){
		return (long)Math.abs(a-b);
	    }

	    public static int max(int a,int b){
		if(a>b)
			return a;
		else
			return b;
	    }

	    public static int min(int a,int b){
		if(a>b)
			return b;
		else
			return a;
	    }

	    public static long max(long a,long b){
		if(a>b)
			return a;
		else
			return b;
	    }

	    public static long min(long a,long b){
		if(a>b)
			return b;
		else
			return a;
	    }

	    public static long pow(long n,long p,long m){
		 long  result = 1;
		  if(p==0)
		    return 1;
		if (p==1)
		    return n;
		while(p!=0)
		{
		    if(p%2==1)
		        result *= n;
		    if(result>=m)
		    result%=m;
		    p >>=1;
		    n*=n;
		    if(n>=m)
		    n%=m;
		}
		return result;
	    }

	    public static long pow(long n,long p){
		long  result = 1;
		  if(p==0)
		    return 1;
		if (p==1)
		    return n;
		while(p!=0)
		{
		    if(p%2==1)
		        result *= n;
		    p >>=1;
		    n*=n;
		}
		return result;
	    }
	    public static void debug(Object... o) {
			System.out.println(Arrays.deepToString(o));
		}
	    void run() throws Exception {
			is = System.in;
			out = new PrintWriter(System.out);
			solve();
			out.flush();
		}

	    public static void main(String[] args) throws Exception {
			new Thread(null, new Runnable() {
				public void run() {
					try {
						new code5().run();
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
			}, "1", 1 << 26).start();

		}
	    private byte[] inbuf = new byte[1024];
		public int lenbuf = 0, ptrbuf = 0;

		private int readByte() {
			if (lenbuf == -1)
				throw new InputMismatchException();
			if (ptrbuf >= lenbuf) {
				ptrbuf = 0;
				try {
					lenbuf = is.read(inbuf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (lenbuf <= 0)
					return -1;
			}
			return inbuf[ptrbuf++];
		}

		private boolean isSpaceChar(int c) {
			return !(c >= 33 && c <= 126);
		}

		private int skip() {
			int b;
			while ((b = readByte()) != -1 && isSpaceChar(b));
			return b;
		}

		private double nd() {
			return Double.parseDouble(ns());
		}

		private char nc() {
			return (char) skip();
		}

		private String ns() {
			int b = skip();
			StringBuilder sb = new StringBuilder();
			while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		private char[] ns(int n) {
			char[] buf = new char[n];
			int b = skip(), p = 0;
			while (p < n && !(isSpaceChar(b))) {
				buf[p++] = (char) b;
				b = readByte();
			}
			return n == p ? buf : Arrays.copyOf(buf, p);
		}

		private char[][] nm(int n, int m) {
			char[][] map = new char[n][];
			for (int i = 0; i < n; i++)
				map[i] = ns(m);
			return map;
		}

		private int[] na(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = ni();
			return a;
		}

		private long[] nl(int n) {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nl();
			return a;
		}

		private int ni() {
			int num = 0, b;
			boolean minus = false;
			while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
				;
			if (b == '-') {
				minus = true;
				b = readByte();
			}

			while (true) {
				if (b >= '0' && b <= '9') {
					num = num * 10 + (b - '0');
				} else {
					return minus ? -num : num;
				}
				b = readByte();
			}
		}

		private long nl() {
			long num = 0;
			int b;
			boolean minus = false;
			while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
				;
			if (b == '-') {
				minus = true;
				b = readByte();
			}

			while (true) {
				if (b >= '0' && b <= '9') {
					num = num * 10 + (b - '0');
				} else {
					return minus ? -num : num;
				}
				b = readByte();
			}
		}

}


import java.util.*;
import java.io.*;
import java.math.*;
public class code5 {
	InputStream is;
	PrintWriter out;
	static long mod=pow(10,9)+7;
	int dx[]= {0,0,1,-1},dy[]={+1,-1,0,0};
	void solve()
	{
		int n=ni();
		Pair p[]=new Pair[n];
		for(int i=0;i<n;i++)
			p[i]=new Pair(ni(),ni(),i);
		Arrays.sort(p);
		long max=p[0].y,index=p[0].i;
		for(int i=1;i<n;i++)
		{
			if(p[i].y<=max)
			{
				System.out.println((p[i].i+1)+" "+(index+1));
				return;
			}
			if(p[i].y>max) {
				max=p[i].y;
				index=p[i].i;
			}
		}
		System.out.println(-1+" "+-1);

	}
	ArrayList<Integer>al [];
	void take(int n,int m)
	{
		al=new ArrayList[n];
		for(int i=0;i<n;i++)
			al[i]=new ArrayList<Integer>();
		for(int i=0;i<m;i++)
		{
			int x=ni()-1;
			int y=ni()-1;
			al[x].add(y);
			al[y].add(x);
		}
	}
	int arr[][];
	int small[];
	void pre(int n)
	{
		small=new int[n+1];
		for(int i=2;i*i<=n;i++)
		{
			for(int j=i;j*i<=n;j++)
			{
				if(small[i*j]==0)
					small[i*j]=i;
			}
		}
		for(int i=0;i<=n;i++)
		{
			if(small[i]==0)
				small[i]=i;
		}
	}
	public static int count(int x)
	{
		int num=0;
		while(x!=0)
		{
			x=x&(x-1);
			num++;
		}
		return num;
	}
	static long d, x, y;
	void extendedEuclid(long A, long B) {
	    if(B == 0) {
	        d = A;
	        x = 1;
	        y = 0;
	    }
	    else {
	        extendedEuclid(B, A%B);
	        long temp = x;
	        x = y;
	        y = temp - (A/B)*y;
	    }
	}
	long modInverse(long A,long M) //A and M are coprime
	{
	    extendedEuclid(A,M);
	    return (x%M+M)%M;    //x may be negative
	}
	public static void mergeSort(int[] arr, int l ,int r){
		if((r-l)>=1){
			int mid = (l+r)/2;
			mergeSort(arr,l,mid);
			mergeSort(arr,mid+1,r);
			merge(arr,l,r,mid);
		}
	}
	public static void merge(int arr[], int l, int r, int mid){
		int n1 = (mid-l+1), n2 = (r-mid);
		int left[] = new int[n1];
		int right[] = new int[n2];
		for(int i =0 ;i<n1;i++) left[i] = arr[l+i];
		for(int i =0 ;i<n2;i++) right[i] = arr[mid+1+i];
		int i =0, j =0, k = l;
		while(i<n1 && j<n2){
			if(left[i]>right[j]){
				arr[k++] = right[j++];
			}
			else{
				arr[k++] = left[i++];
			}
		}
		while(i<n1) arr[k++] = left[i++];
		while(j<n2) arr[k++] = right[j++];
	}
	public static void mergeSort(long[] arr, int l ,int r){
		if((r-l)>=1){
			int mid = (l+r)/2;
			mergeSort(arr,l,mid);
			mergeSort(arr,mid+1,r);
			merge(arr,l,r,mid);
		}
	}
	public static void merge(long arr[], int l, int r, int mid){
		int n1 = (mid-l+1), n2 = (r-mid);
		long left[] = new long[n1];
		long right[] = new long[n2];
		for(int i =0 ;i<n1;i++) left[i] = arr[l+i];
		for(int i =0 ;i<n2;i++) right[i] = arr[mid+1+i];
		int i =0, j =0, k = l;
		while(i<n1 && j<n2){
			if(left[i]>right[j]){
				arr[k++] = right[j++];
			}
			else{
				arr[k++] = left[i++];
			}
		}
		while(i<n1) arr[k++] = left[i++];
		while(j<n2) arr[k++] = right[j++];
	}
	 static class Pair implements Comparable<Pair>{

	      long x;
	      long y,k,i;
		Pair (long x,long y,long i){
			this.x=x;
			this.y=y;
			this.i=i;
		}

		public int compareTo(Pair o) {
			if(this.x!=o.x)
				return Long.compare(this.x,o.x);
			return  Long.compare(o.y,this.y);
		}
		public boolean equals(Object o) {
			if (o instanceof Pair) {
				Pair p = (Pair)o;
				return p.x == x && p.y == y;
			}
			return false;
		}
		public int hashCode() {
			return new Long(x).hashCode()*31 + new Long(y).hashCode() ;
		}

	        @Override
	        public String toString() {
	            return  "("+x + " " + y +" "+k+" "+i+" )";
	        }

	    }

	    public static boolean isPal(String s){
	        for(int i=0, j=s.length()-1;i<=j;i++,j--){
	                if(s.charAt(i)!=s.charAt(j)) return false;
	        }
	        return true;
	    }
	    public static String rev(String s){
			StringBuilder sb=new StringBuilder(s);
			sb.reverse();
			return sb.toString();
	    }

	    public static long gcd(long x,long y){
		if(x%y==0)
			return y;
		else
			return gcd(y,x%y);
	    }

	    public static int gcd(int x,int y){
	    	if(y==0)
	    		return x;
	    	return gcd(y,x%y);
	    }

	    public static long gcdExtended(long a,long b,long[] x){

	        if(a==0){
	            x[0]=0;
	            x[1]=1;
	            return b;
	        }
	        long[] y=new long[2];
	        long gcd=gcdExtended(b%a, a, y);

	        x[0]=y[1]-(b/a)*y[0];
	        x[1]=y[0];

	        return gcd;
	    }

	    public static int abs(int a,int b){
		return (int)Math.abs(a-b);
	    }

	    public static long abs(long a,long b){
		return (long)Math.abs(a-b);
	    }

	    public static int max(int a,int b){
		if(a>b)
			return a;
		else
			return b;
	    }

	    public static int min(int a,int b){
		if(a>b)
			return b;
		else
			return a;
	    }

	    public static long max(long a,long b){
		if(a>b)
			return a;
		else
			return b;
	    }

	    public static long min(long a,long b){
		if(a>b)
			return b;
		else
			return a;
	    }

	    public static long pow(long n,long p,long m){
		 long  result = 1;
		  if(p==0)
		    return 1;
		if (p==1)
		    return n;
		while(p!=0)
		{
		    if(p%2==1)
		        result *= n;
		    if(result>=m)
		    result%=m;
		    p >>=1;
		    n*=n;
		    if(n>=m)
		    n%=m;
		}
		return result;
	    }

	    public static long pow(long n,long p){
		long  result = 1;
		  if(p==0)
		    return 1;
		if (p==1)
		    return n;
		while(p!=0)
		{
		    if(p%2==1)
		        result *= n;
		    p >>=1;
		    n*=n;
		}
		return result;
	    }
	    public static void debug(Object... o) {
			System.out.println(Arrays.deepToString(o));
		}
	    void run() throws Exception {
			is = System.in;
			out = new PrintWriter(System.out);
			solve();
			out.flush();
		}

	    public static void main(String[] args) throws Exception {
			new Thread(null, new Runnable() {
				public void run() {
					try {
						new code5().run();
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
			}, "1", 1 << 26).start();

		}
	    private byte[] inbuf = new byte[1024];
		public int lenbuf = 0, ptrbuf = 0;

		private int readByte() {
			if (lenbuf == -1)
				throw new InputMismatchException();
			if (ptrbuf >= lenbuf) {
				ptrbuf = 0;
				try {
					lenbuf = is.read(inbuf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (lenbuf <= 0)
					return -1;
			}
			return inbuf[ptrbuf++];
		}

		private boolean isSpaceChar(int c) {
			return !(c >= 33 && c <= 126);
		}

		private int skip() {
			int b;
			while ((b = readByte()) != -1 && isSpaceChar(b));
			return b;
		}

		private double nd() {
			return Double.parseDouble(ns());
		}

		private char nc() {
			return (char) skip();
		}

		private String ns() {
			int b = skip();
			StringBuilder sb = new StringBuilder();
			while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		private char[] ns(int n) {
			char[] buf = new char[n];
			int b = skip(), p = 0;
			while (p < n && !(isSpaceChar(b))) {
				buf[p++] = (char) b;
				b = readByte();
			}
			return n == p ? buf : Arrays.copyOf(buf, p);
		}

		private char[][] nm(int n, int m) {
			char[][] map = new char[n][];
			for (int i = 0; i < n; i++)
				map[i] = ns(m);
			return map;
		}

		private int[] na(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = ni();
			return a;
		}

		private long[] nl(int n) {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nl();
			return a;
		}

		private int ni() {
			int num = 0, b;
			boolean minus = false;
			while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
				;
			if (b == '-') {
				minus = true;
				b = readByte();
			}

			while (true) {
				if (b >= '0' && b <= '9') {
					num = num * 10 + (b - '0');
				} else {
					return minus ? -num : num;
				}
				b = readByte();
			}
		}

		private long nl() {
			long num = 0;
			int b;
			boolean minus = false;
			while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
				;
			if (b == '-') {
				minus = true;
				b = readByte();
			}

			while (true) {
				if (b >= '0' && b <= '9') {
					num = num * 10 + (b - '0');
				} else {
					return minus ? -num : num;
				}
				b = readByte();
			}
		}

}


import java.util.*;
import java.io.*;
import java.math.*;
public class code5 {
	InputStream is;
	PrintWriter out;
	static long mod=pow(10,9)+7;
	int dx[]= {0,0,1,-1},dy[]={+1,-1,0,0};
	void solve()
	{
		int n=ni();
		Pair p[]=new Pair[n];
		for(int i=0;i<n;i++)
			p[i]=new Pair(ni(),ni(),i);
		Arrays.sort(p);
		long max=p[0].y,index=p[0].i;
		for(int i=1;i<n;i++)
		{
			if(p[i].y<=max)
			{
				System.out.println((p[i].i+1)+" "+(index+1));
				return;
			}
			max=Math.max(max,p[i].y);
		}
		System.out.println(-1+" "+-1);

	}
	ArrayList<Integer>al [];
	void take(int n,int m)
	{
		al=new ArrayList[n];
		for(int i=0;i<n;i++)
			al[i]=new ArrayList<Integer>();
		for(int i=0;i<m;i++)
		{
			int x=ni()-1;
			int y=ni()-1;
			al[x].add(y);
			al[y].add(x);
		}
	}
	int arr[][];
	int small[];
	void pre(int n)
	{
		small=new int[n+1];
		for(int i=2;i*i<=n;i++)
		{
			for(int j=i;j*i<=n;j++)
			{
				if(small[i*j]==0)
					small[i*j]=i;
			}
		}
		for(int i=0;i<=n;i++)
		{
			if(small[i]==0)
				small[i]=i;
		}
	}
	public static int count(int x)
	{
		int num=0;
		while(x!=0)
		{
			x=x&(x-1);
			num++;
		}
		return num;
	}
	static long d, x, y;
	void extendedEuclid(long A, long B) {
	    if(B == 0) {
	        d = A;
	        x = 1;
	        y = 0;
	    }
	    else {
	        extendedEuclid(B, A%B);
	        long temp = x;
	        x = y;
	        y = temp - (A/B)*y;
	    }
	}
	long modInverse(long A,long M) //A and M are coprime
	{
	    extendedEuclid(A,M);
	    return (x%M+M)%M;    //x may be negative
	}
	public static void mergeSort(int[] arr, int l ,int r){
		if((r-l)>=1){
			int mid = (l+r)/2;
			mergeSort(arr,l,mid);
			mergeSort(arr,mid+1,r);
			merge(arr,l,r,mid);
		}
	}
	public static void merge(int arr[], int l, int r, int mid){
		int n1 = (mid-l+1), n2 = (r-mid);
		int left[] = new int[n1];
		int right[] = new int[n2];
		for(int i =0 ;i<n1;i++) left[i] = arr[l+i];
		for(int i =0 ;i<n2;i++) right[i] = arr[mid+1+i];
		int i =0, j =0, k = l;
		while(i<n1 && j<n2){
			if(left[i]>right[j]){
				arr[k++] = right[j++];
			}
			else{
				arr[k++] = left[i++];
			}
		}
		while(i<n1) arr[k++] = left[i++];
		while(j<n2) arr[k++] = right[j++];
	}
	public static void mergeSort(long[] arr, int l ,int r){
		if((r-l)>=1){
			int mid = (l+r)/2;
			mergeSort(arr,l,mid);
			mergeSort(arr,mid+1,r);
			merge(arr,l,r,mid);
		}
	}
	public static void merge(long arr[], int l, int r, int mid){
		int n1 = (mid-l+1), n2 = (r-mid);
		long left[] = new long[n1];
		long right[] = new long[n2];
		for(int i =0 ;i<n1;i++) left[i] = arr[l+i];
		for(int i =0 ;i<n2;i++) right[i] = arr[mid+1+i];
		int i =0, j =0, k = l;
		while(i<n1 && j<n2){
			if(left[i]>right[j]){
				arr[k++] = right[j++];
			}
			else{
				arr[k++] = left[i++];
			}
		}
		while(i<n1) arr[k++] = left[i++];
		while(j<n2) arr[k++] = right[j++];
	}
	 static class Pair implements Comparable<Pair>{

	      long x;
	      long y,k,i;
		Pair (long x,long y,long i){
			this.x=x;
			this.y=y;
			this.i=i;
		}

		public int compareTo(Pair o) {
			if(this.x!=o.x)
				return Long.compare(this.x,o.x);
			return  Long.compare(this.y,o.y);
		}
		public boolean equals(Object o) {
			if (o instanceof Pair) {
				Pair p = (Pair)o;
				return p.x == x && p.y == y;
			}
			return false;
		}
		public int hashCode() {
			return new Long(x).hashCode()*31 + new Long(y).hashCode() ;
		}

	        @Override
	        public String toString() {
	            return  "("+x + " " + y +" "+k+" "+i+" )";
	        }

	    }

	    public static boolean isPal(String s){
	        for(int i=0, j=s.length()-1;i<=j;i++,j--){
	                if(s.charAt(i)!=s.charAt(j)) return false;
	        }
	        return true;
	    }
	    public static String rev(String s){
			StringBuilder sb=new StringBuilder(s);
			sb.reverse();
			return sb.toString();
	    }

	    public static long gcd(long x,long y){
		if(x%y==0)
			return y;
		else
			return gcd(y,x%y);
	    }

	    public static int gcd(int x,int y){
	    	if(y==0)
	    		return x;
	    	return gcd(y,x%y);
	    }

	    public static long gcdExtended(long a,long b,long[] x){

	        if(a==0){
	            x[0]=0;
	            x[1]=1;
	            return b;
	        }
	        long[] y=new long[2];
	        long gcd=gcdExtended(b%a, a, y);

	        x[0]=y[1]-(b/a)*y[0];
	        x[1]=y[0];

	        return gcd;
	    }

	    public static int abs(int a,int b){
		return (int)Math.abs(a-b);
	    }

	    public static long abs(long a,long b){
		return (long)Math.abs(a-b);
	    }

	    public static int max(int a,int b){
		if(a>b)
			return a;
		else
			return b;
	    }

	    public static int min(int a,int b){
		if(a>b)
			return b;
		else
			return a;
	    }

	    public static long max(long a,long b){
		if(a>b)
			return a;
		else
			return b;
	    }

	    public static long min(long a,long b){
		if(a>b)
			return b;
		else
			return a;
	    }

	    public static long pow(long n,long p,long m){
		 long  result = 1;
		  if(p==0)
		    return 1;
		if (p==1)
		    return n;
		while(p!=0)
		{
		    if(p%2==1)
		        result *= n;
		    if(result>=m)
		    result%=m;
		    p >>=1;
		    n*=n;
		    if(n>=m)
		    n%=m;
		}
		return result;
	    }

	    public static long pow(long n,long p){
		long  result = 1;
		  if(p==0)
		    return 1;
		if (p==1)
		    return n;
		while(p!=0)
		{
		    if(p%2==1)
		        result *= n;
		    p >>=1;
		    n*=n;
		}
		return result;
	    }
	    public static void debug(Object... o) {
			System.out.println(Arrays.deepToString(o));
		}
	    void run() throws Exception {
			is = System.in;
			out = new PrintWriter(System.out);
			solve();
			out.flush();
		}

	    public static void main(String[] args) throws Exception {
			new Thread(null, new Runnable() {
				public void run() {
					try {
						new code5().run();
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
			}, "1", 1 << 26).start();

		}
	    private byte[] inbuf = new byte[1024];
		public int lenbuf = 0, ptrbuf = 0;

		private int readByte() {
			if (lenbuf == -1)
				throw new InputMismatchException();
			if (ptrbuf >= lenbuf) {
				ptrbuf = 0;
				try {
					lenbuf = is.read(inbuf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (lenbuf <= 0)
					return -1;
			}
			return inbuf[ptrbuf++];
		}

		private boolean isSpaceChar(int c) {
			return !(c >= 33 && c <= 126);
		}

		private int skip() {
			int b;
			while ((b = readByte()) != -1 && isSpaceChar(b));
			return b;
		}

		private double nd() {
			return Double.parseDouble(ns());
		}

		private char nc() {
			return (char) skip();
		}

		private String ns() {
			int b = skip();
			StringBuilder sb = new StringBuilder();
			while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		private char[] ns(int n) {
			char[] buf = new char[n];
			int b = skip(), p = 0;
			while (p < n && !(isSpaceChar(b))) {
				buf[p++] = (char) b;
				b = readByte();
			}
			return n == p ? buf : Arrays.copyOf(buf, p);
		}

		private char[][] nm(int n, int m) {
			char[][] map = new char[n][];
			for (int i = 0; i < n; i++)
				map[i] = ns(m);
			return map;
		}

		private int[] na(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = ni();
			return a;
		}

		private long[] nl(int n) {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nl();
			return a;
		}

		private int ni() {
			int num = 0, b;
			boolean minus = false;
			while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
				;
			if (b == '-') {
				minus = true;
				b = readByte();
			}

			while (true) {
				if (b >= '0' && b <= '9') {
					num = num * 10 + (b - '0');
				} else {
					return minus ? -num : num;
				}
				b = readByte();
			}
		}

		private long nl() {
			long num = 0;
			int b;
			boolean minus = false;
			while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
				;
			if (b == '-') {
				minus = true;
				b = readByte();
			}

			while (true) {
				if (b >= '0' && b <= '9') {
					num = num * 10 + (b - '0');
				} else {
					return minus ? -num : num;
				}
				b = readByte();
			}
		}

}


#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
long long  a[100000000];
int main ()
{
	long long k,n,sum,s;
	int i = 1;
	s = 0;
	scanf("%I64d %I64d",&k,&n);
	while (n > 0)
	{
		a[i] = n%10;
		s += a[i];
		n /= 10;
		i++;
		}
		if (s >= k) printf("0");
		else {
			for (int j = 1; j <= i-1; j++)
			{
				s += 9 - a[j];
				if (s >= k)
				{
					printf("%d",j);
					return 0;
					}
				}
			}

	}


#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
char n[1000000];
bool cmp (char a,char b)
{
	return a>b;
}
int main ()
{
	long long  k,sum,s;
	int i,len,j;
	s = 0;
	scanf("%I64d",&k);
	scanf(" %s",&n);
	len = strlen(n);
	sort(n,n+len,cmp);
	for (i = 0; i < len; i++)
	{
		s += n[i] - 48;
	}
	if (s >= k) printf("0");
	else {
		for (i = len-1,j = 1; i >= 0; i--,j++)
		{
			s += 9 - (n[i] - 48);
			if (s >= k)
			{
				printf("%d",j);
				return 0;
			}
		}
	}
}


#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
char n[1000000];
int main ()
{
	long long  k,sum,s;
	int i,len,j;
	s = 0;
	scanf("%I64d",&k);
	scanf(" %s",&n);
	len = strlen(n);
	sort(n,n+len);
	for (i = 0; i < len; i++)
	{
		s += n[i] - 48;
	}
	if (s >= k) printf("0");
	else {
		for (j = 0; j < len; j++)
		{
			s += 9 - (n[j] - 48);
			if (s >= k)
			{
				printf("%d",j+1);
				return 0;
			}
		}
	}
}


#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
char n[1000000];
int main ()
{
	long long  k,sum,s;
	int i,len,j;
	s = 0;
	scanf("%I64d",&k);
	scanf(" %s",&n);
	len = strlen(n);
	sort(n,n+len-1);
	for (i = 0; i < len; i++)
	{
		s += n[i] - 48;
	}
	if (s >= k) printf("0");
	else {
		for (j = 1; j <= len - 1; j++)
		{
			s += 9 - (n[j] - 48);
			if (s >= k)
			{
				printf("%d",j);
				return 0;
			}
		}
	}
}


#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{

    int k;
    cin>>k;
    int ar[101]={0};
      string s;
    cin>>s;
    int flag=0;
    long int sum=0;
    for(int i=0;i<s.size();i++)
    {
        sum=sum+s[i]-48;
        ar[s[i]-48]=ar[s[i]-48]+1;
        if(sum>=k)
        {
            cout<<0;
            flag=1;
        break;

        }
    }
    int count=0;

    for(int i=0;i<=8;i++)
    {
        for(int j=0;j<ar[i];j++)
        {
            sum=sum+(9-(i));
            count++;
            if(sum>=k)
            {

                flag=2;
            break;
            }
        }if(flag==2)
        break;
    }
     if(flag!=1)
    cout<<count<<endl;
}


#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{

    int k;
    cin>>k;
    int ar[101]={0};
      string s;
    cin>>s;
    int flag=0;
    long int sum=0;
    for(int i=0;i<s.size();i++)
    {
        sum=sum+s[i]-48;
        ar[s[i]-48]=ar[s[i]-48]+1;
        if(sum>=k)
        {
            cout<<0;
            flag=1;
        break;

        }
    }
    int count=0;
   int flag1=9;
    for(int i=0;i<=8;i++)
    {
        for(int j=0;j<ar[i];j++)
        {
            sum=sum+(9-(i));
            count++;
            if(sum>=k)
            {

                flag1=2;
            break;
            }
        }if(flag1==2)
        break;
    }
     if(flag!=1)
    cout<<count<<endl;
}


#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{

    int k;
    cin>>k;
    int ar[101]={0};
      string s;
    cin>>s;
    int flag=0;
    long int sum=0;
    for(int i=0;i<s.size();i++)
    {
        sum=sum+s[i]-48;
        ar[s[i]-48]=ar[s[i]-48]+1;
        if(sum>=k)
        {
            cout<<0;
            flag=1;
        break;

        }
    }

    int count=0;
   int flag1=9;
    for(int i=0;i<=8;i++)
    {
        for(int j=0;j<ar[i];j++)
        {
            sum=sum+(9-(i));
            count++;
            if(sum>=k)
            {

                flag1=2;
            break;
            }
        }if(flag1==2)
        break;
    }
     if(flag!=1)
    cout<<count<<endl;
}


#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{

    int k;
    cin>>k;
      string s;
    cin>>s;
    int flag=0;
    long int sum=0;
    for(int i=0;i<s.size();i++)
    {
        sum=sum+s[i]-48;
        if(sum>=k)
        {
            cout<<0;
            flag=1;
        break;

        }
    }
    int count=0;

    for(int i=0;i<s.size();i++)
    {
       // cout<<s[i];
        if(s[i]!='9')

       {

           sum=sum+(9-(s[i]-48));
        count++;
       }
        if(sum>=k)
        break;
    }if(flag!=1)
    cout<<count<<endl;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<string>
#include<stdio.h>
using namespace std;

#define pb push_back
#define ll long long
#define mp make_pair
#define vec vector

int main()
{
	char s;
	vec <char> n;
	ll k,temp,sum=0,i,j=0;
	vec <int> digits;
	cin>>k;
	while(scanf("%c",&s)!= EOF)
	{
		if(s!='\n')
		{
			sum+=s-'0';
			n.pb(s);
		}
	}
	sum=k-sum;
	sort(n.begin(),n.end());
	/*for (int i = 0; i < n.size(); ++i)
		cout<<n[i];
	cout<<endl;*/
	//cout<<n.size();
	i=0;
	if(sum<=0)
		cout<<"0";
	else
	{
		while(sum>0 && i<n.size())
		{
			sum-=9-(n[i]-'0');
			i++;
			j++;
		}
		cout<<j;
	}
	return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<string>
using namespace std;

#define pb push_back
#define ll long long
#define mp make_pair
#define vec vector

int main()
{
	ll k,n,temp,sum=0,i;
	vec <int> digits;
	cin>>k>>n;
	temp=n;
	while(temp!=0)
	{
		digits.pb(temp%10);
		temp=temp/10;
	}
	for (i = 0; i < digits.size(); ++i)
		sum+=digits[i];
	sum=k-sum;
	i--;
	if(sum<=0)
		cout<<"0";
	else
	{
		while(sum>0 && i>=0)
		{
			sum-=9-digits[i];
			i--;
		}
		cout<<(i-digits.size()+3);
	}
	return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<string>
using namespace std;

#define pb push_back
#define ll long long
#define mp make_pair
#define vec vector

int main()
{
	ll k,n,temp,sum=0,i;
	vec <int> digits;
	cin>>k>>n;
	temp=n;
	while(temp%10!=0)
	{
		digits.pb(temp%10);
		temp=temp/10;
	}
	for (i = 0; i < digits.size(); ++i)
		sum+=digits[i];
	sum=k-sum;
	i--;
	if(sum<=0)
		cout<<"0";
	else
	{
		while(i>=0)
		{
			while(digits[i]<9 && sum>0)
			{
				digits[i]++;
				sum--;
			}
			i--;
		}
		for (i = 0; i < digits.size()-1; ++i)
		{
			sum+=digits[i];
			sum*=10;
		}
		sum+=digits[i];
		cout<<sum-n;
	}
	return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<string>
using namespace std;

#define pb push_back
#define ll long long
#define mp make_pair
#define vec vector

int main()
{
	ll k,n,temp,sum=0,i;
	vec <int> digits;
	cin>>k>>n;
	temp=n;
	while(temp%10!=0)
	{
		digits.pb(temp%10);
		temp=temp/10;
	}
	for (i = 0; i < digits.size(); ++i)
		sum+=digits[i];
	sum=k-sum;
	i--;
	if(sum<=0)
		cout<<"0";
	else
	{
		while(sum>0 && i>=0)
		{
			sum-=9-digits[i];
			i--;
		}
		cout<<(i-digits.size()+3);
	}
	return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<string>
using namespace std;

#define pb push_back
#define ll long long
#define mp make_pair
#define vec vector

int main()
{
	ll k,n,temp,sum=0,i;
	vec <int> digits;
	cin>>k>>n;
	temp=n;
	while(temp!=0)
	{
		digits.pb(temp%10);
		temp=temp/10;
	}
	for (i = 0; i < digits.size(); ++i)
		sum+=digits[i];
	sum=k-sum;
	i--;
	if(sum<=0)
		cout<<"0";
	else
	{
		while(sum>0 && i>=0)
		{
			sum-=9-digits[i];
			i--;
		}
		cout<<(digits.size()-i-1);
	}
	return 0;
}


#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;

long long k, ans, flag[15], sum;
char a[100005];
int main()
{
	sum = 0;
	ans = 0;
	scanf("%d", &k);
	scanf("%s", a + 1);
	int len = strlen(a + 1);
	for(int i = 1; i <= len; i++)
	{
		ans = ans + (a[i] - '0');
	}
	if(ans >= k)  printf("0\n");
	else {
		for(int i = 1; i <= len; i++)
		{
			int tt = a[i] - '0';
			printf("%d\n", tt);
			flag[tt]++;
		}
		int pp = 0;
		long long cha = k - ans;
		while(true)
		{
			if(pp > 10) break;
			if(flag[pp] != 0) {
				if(cha <= (9 - pp) * flag[pp]) {
					sum = cha / (9 - pp);
					if(cha % (9 - pp) != 0) sum++;
					cha = 0;
					break;
				}
				else {
					cha = cha - (9 - pp) * flag[pp];
					sum += flag[pp];
				}
				flag[pp] = 0;
			}
			else pp++;
		}
		if(cha != 0) {
			sum = sum + cha / 9;
			if(cha % 9 != 0) sum++;
		}
		printf("%d\n", sum);
	}
	return 0;
}


#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;

long long k, ans, flag[15], sum;
char a[100005];
int main()
{
	sum = 0;
	ans = 0;
	scanf("%d", &k);
	scanf("%s", a + 1);
	int len = strlen(a + 1);
	for(int i = 1; i <= len; i++)
	{
		ans = ans + (a[i] - '0');
	}
	if(ans >= k)  printf("0\n");
	else {
		for(int i = 1; i <= len; i++)
		{
			int tt = a[i] - '0';
			flag[tt]++;
		}
		int pp = 0;
		long long cha = k - ans;
		while(true)
		{
			if(pp > 10) break;
			if(flag[pp] != 0) {
				if(cha <= (9 - pp) * flag[pp]) {
					sum = cha / (9 - pp);
					if(cha % (9 - pp) != 0) sum++;
					break;
				}
				else {
					cha = cha - (9 - pp) * flag[pp];
					sum += flag[pp];
				}
				flag[pp] = 0;
			}
			else pp++;
		}
		printf("%d\n", sum);
	}
	return 0;
}


#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;

long long k, ans, flag[15], sum;
char a[100005];
int main()
{
	sum = 0;
	ans = 0;
	scanf("%d", &k);
	scanf("%s", a + 1);
	int len = strlen(a + 1);
	for(int i = 1; i <= len; i++)
	{
		ans = ans + a[i] - '0';
	}
	if(ans >= k)  printf("0\n");
	else {
		for(int i = 1; i <= len; i++)
		{
			flag[a[i] - '0']++;
		}
		int pp = 0;
		long long cha = k - ans;
		while(true)
		{
			if(pp > 10) break;
			if(flag[pp] != 0) {
				if(cha < (9 - pp) * flag[pp]) {
					sum = cha / (9 - pp);
					if(cha % (9 - pp) != 0) sum++;
					break;
				}
				else {
					cha = cha - (9 - pp) * flag[pp];
					sum += flag[pp];
				}
			}
			else pp++;
		}
		printf("%d\n", sum);
	}
	return 0;
}


#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;

long long k, ans, flag[15], sum;
char a[1000005];
int main()
{
	sum = 0;
	ans = 0;
	scanf("%d", &k);
	scanf("%s", a + 1);
	int len = strlen(a + 1);
	for(int i = 1; i <= len; i++)
	{
		ans = ans + (a[i] - '0');
	}
	if(ans >= k)  printf("0\n");
	else {
		for(int i = 1; i <= len; i++)
		{
			int tt = a[i] - '0';
			flag[tt]++;
		}
		int pp = 0;
		long long cha = k - ans;
		while(true)
		{
			if(pp > 10) break;
			if(flag[pp] != 0) {
				if(cha <= (9 - pp) * flag[pp]) {
					sum = cha / (9 - pp);
					if(cha % (9 - pp) != 0) sum++;
					cha = 0;
					break;
				}
				else {
					cha = cha - (9 - pp) * flag[pp];
					sum += flag[pp];
				}
				flag[pp] = 0;
			}
			else pp++;
		}
		if(cha != 0) {
			sum = sum + cha / 9;
			if(cha % 9 != 0) sum++;
		}
		printf("%d\n", sum);
	}
	return 0;
}


#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;

long long k, ans, flag[15], sum;
char a[100005];
int main()
{
	sum = 0;
	ans = 0;
	scanf("%d", &k);
	scanf("%s", a + 1);
	int len = strlen(a + 1);
	for(int i = 1; i <= len; i++)
	{
		ans = ans + (a[i] - '0');
	}
	if(ans >= k)  printf("0\n");
	else {
		for(int i = 1; i <= len; i++)
		{
			int tt = a[i] - '0';
			flag[tt]++;
		}
		int pp = 0;
		long long cha = k - ans;
		while(true)
		{
			if(pp > 10) break;
			if(flag[pp] != 0) {
				if(cha < (9 - pp) * flag[pp]) {
					sum = cha / (9 - pp);
					if(cha % (9 - pp) != 0) sum++;
					break;
				}
				else {
					cha = cha - (9 - pp) * flag[pp];
					sum += flag[pp];
				}
				flag[pp] = 0;
			}
			else pp++;
		}
		printf("%d\n", sum);
	}
	return 0;
}


#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;

long long k, ans, flag[15], sum;
char a[100005];
int main()
{
	sum = 0;
	ans = 0;
	scanf("%d", &k);
	scanf("%s", a + 1);
	int len = strlen(a + 1);
	for(int i = 1; i <= len; i++)
	{
		ans = ans + (a[i] - '0');
	}
	if(ans >= k)  printf("0\n");
	else {
		for(int i = 1; i <= len; i++)
		{
			int tt = a[i] - '0';
			printf("%d\n", tt);
			flag[tt]++;
		}
		int pp = 0;
		long long cha = k - ans;
		while(true)
		{
			if(pp > 10) break;
			if(flag[pp] != 0) {
				if(cha <= (9 - pp) * flag[pp]) {
					sum = cha / (9 - pp);
					if(cha % (9 - pp) != 0) sum++;
					break;
				}
				else {
					cha = cha - (9 - pp) * flag[pp];
					sum += flag[pp];
				}
				flag[pp] = 0;
			}
			else pp++;
		}
		if(cha != 0) {
			sum = sum + cha / 9;
			if(cha % 9 != 0) sum++;
		}
		printf("%d\n", sum);
	}
	return 0;
}


#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;

long long k, ans, flag[15], sum;
char a[100005];
int main()
{
	sum = 0;
	ans = 0;
	scanf("%d", &k);
	scanf("%s", a + 1);
	int len = strlen(a + 1);
	for(int i = 1; i <= len; i++)
	{
		ans = ans + (a[i] - '0');
	}
	if(ans >= k)  printf("0\n");
	else {
		for(int i = 1; i <= len; i++)
		{
			int tt = a[i] - '0';
			flag[tt]++;
		}
		int pp = 0;
		long long cha = k - ans;
		while(true)
		{
			if(pp > 10) break;
			if(flag[pp] != 0) {
				if(cha <= (9 - pp) * flag[pp]) {
					sum = cha / (9 - pp);
					if(cha % (9 - pp) != 0) sum++;
					cha = 0;
					break;
				}
				else {
					cha = cha - (9 - pp) * flag[pp];
					sum += flag[pp];
				}
				flag[pp] = 0;
			}
			else pp++;
		}
		if(cha != 0) {
			sum = sum + cha / 9;
			if(cha % 9 != 0) sum++;
		}
		printf("%d\n", sum);
	}
	return 0;
}


#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;

long long k, ans, flag[15], sum;
char a[1000005];
int main()
{
	sum = 0;
	ans = 0;
	scanf("%d", &k);
	scanf("%s", a + 1);
	int len = strlen(a + 1);
	for(int i = 1; i <= len; i++)
	{
		ans = ans + (a[i] - '0');
	}
	if(ans >= k)  printf("0\n");
	else {
		for(int i = 1; i <= len; i++)
		{
			int tt = a[i] - '0';
			flag[tt]++;
		}
		int pp = 0;
		long long cha = k - ans;
		while(true)
		{
			if(pp > 10) break;
			if(flag[pp] != 0) {
				if(cha <= (9 - pp) * flag[pp]) {
					sum = sum + cha / (9 - pp);
					if(cha % (9 - pp) != 0) sum++;
					cha = 0;
					break;
				}
				else {
					cha = cha - (9 - pp) * flag[pp];
					sum += flag[pp];
				}
				flag[pp] = 0;
			}
			else pp++;
		}
		if(cha != 0) {
			sum = sum + cha / 9;
			if(cha % 9 != 0) sum++;
		}
		printf("%d\n", sum);
	}
	return 0;
}


#include <iostream>
#include <string>
using namespace std;
int a[10];

int main()
{
	int n;
	cin>>n;
	string ar;
	cin>>ar;
	int sum = 0;
	for(int i=0;i<ar.length();i++)
	{
		a[ar[i]-'0']++;
		sum += ar[i] - '0';
	}

	n -= sum;
	int count=0;
	int flag = 0;
	if(n<=0)
		count = 0;
	else
	{
		for(int i=0;i<10;i++)
		{
			while(a[i]>0)
			{
				n -= (9-i);
				count++;
				a[i]--;
				if(n<=0)
				{
					flag = 1;
					break;
				}
			}
			if(flag==1)
				break;
		}
	}
	cout<<count;
	return 0;
}


#include <iostream>
#include <string>
using namespace std;
int a[10];

int main()
{
	int n;
	cin>>n;
	string ar;
	cin>>ar;
	int sum = 0;
	for(int i=0;i<ar.length();i++)
	{
		a[ar[i]-'0']++;
		sum += ar[i] - '0';
	}

	n -= sum;
	int count=0;
	if(n<=0)
		count = 0;
	else
	{
		for(int i=0;i<10;i++)
		{
			while(a[i]>0)
			{
				n -= (9-i);
				count++;
				a[i]--;
				if(n<=0)
					break;
			}
		}
	}
	cout<<count;
	return 0;
}


#include <iostream>
#include <string>
using namespace std;
int a[10];

int main()
{
	int n;
	cin>>n;
	string ar;
	cin>>ar;
	int sum = 0;
	for(int i=0;i<ar.length();i++)
	{
		a[ar[i]-'0']++;
		sum += ar[i] - '0';
	}

	n -= sum;
	int count=0;
	if(n<=0)
		count = 0;
	else
	{
		for(int i=0;i<10;i++)
		{
			if(a[i]>0)
			{
				n -= (9-i);
				count++;
				if(n<=0)
					break;
			}
		}
	}
	cout<<count;
	return 0;
}


#include <iostream>
#include <string>
using namespace std;
int a[10];

int main()
{
	int n;
	cin>>n;
	string ar;
	cin>>ar;
	int sum = 0;
	for(int i=0;i<ar.length();i++)
	{
		a[ar[i]-'0']++;
		sum += ar[i] - '0';
	}

	n -= sum;
	int count=0;
	if(n<=0)
		count = 0;
	else
	{
		for(int i=0;i<10;i++)
		{
			while(a[i]>0)
			{
				n -= (9-i);
				count++;
				a[i]--;
				if(n<=0)
					break;
			}
		}
		cout<<"here";
	}
	cout<<count;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main (){
	int k,digit=0, dif;
	string n;
	cin>>k;
	cin>>n;
	for (int i=0;i<n.size();++i){
		char c=n[i] - '0';
		digit+=c;
	}
	dif=k-digit;
	if (dif<=0) cout<<0<<'\n';
	else cout << (dif + 9)/10<<'\n';
	return 0;
}
// 1523044495244


#include <bits/stdc++.h>
using namespace std;

int pasar_a_int(string n){
    int ans = 0;
    for (int i = 0; i < n.size(); i++){
        ans *= 10;
        ans += n[i] - '0';
    }
    return ans;

}

int main(){
	int k;
	string ene;

	cin >> k;
	cin >> ene;

	int sum = 0;
	int vals[ene.size()];

	for(int i = 0; i < ene.size(); i++){
		sum += ene[i]-'0';
		vals[i] = ene[i]-'0';
	}
	sort(vals, vals + ene.size());

	int dif;
	dif = k - sum;

	if(dif <= 0){
		cout << 0 << endl;
		return 0;
	}

	int i = 0;
	while(dif > 0){
		dif -= (9 - vals[i]);
		i += 1;
	}

	cout << i  <<endl;

	return 0;

}
// 1523041298973


#include <bits/stdc++.h>
using namespace std;

int main() {
	int k;
	string n;
	cin >> k >> n;
	int count=0;
	int sum = 0;
	sort(n.begin(),n.end());
	for (int i = 0; i<n.size(); i++){
		int numero = n[i] - '0';
		sum += numero;
	}
	if (sum>=k){
		cout << 0<<endl;
	}
	else{
	for(int i=0;i<n.size();i++){
		while( sum <k){
			if ( n[i]-'0'==9){ break;}
			sum=sum -(n[i]-'0')+9;
			count++;
		}

	}cout<<count<<endl;
}

	return 0;

}
// 1523048092371


#include <bits/stdc++.h>
using namespace std;

int main() {
	int k;
	string n;
	cin >> k >> n;
	int count=0;
	int sum = 0;
	sort(n.begin(),n.end());
	for (int i = 0; i<n.size(); i++){
		int numero = n[i] - '0';
		sum += numero;
	}
	if (sum>=k){
		cout << 0<<endl;
	}
	else{
	for(int i=0;i<n.size();i++){
		while( sum <k){
			sum=sum -(n[i]-'0')+9;
			count++;
		}

	}cout<<count<<endl;
}

	return 0;

}
// 1523047638532


#include<cstdio>
char s;
int cnt[10];
int main()
{
	int k,ans=0,tmp;
	scanf("%d", &k);
	while (scanf("%c", &s) != EOF)
	{
		if (s >= '0'&&s <= '9')
		{
			k -= s - '0';
			cnt[s - '0']++;
		}
	}
	if (k <= 0)
		printf("0");
	else
	{
		for (int i = 0; i < 9; i++)
		{
			tmp = k / (9 - i);
			if (tmp > cnt[i])
			{
				k -= cnt[i] * (9 - i);
				ans += cnt[i];
			}
			else
			{
				k -= tmp * (9 - i);
				ans += tmp;
			}
		}
		printf("%d", ans);
	}
		//printf("%d",k);
}


#include<cstdio>
char s;
int cnt[10];
int main()
{
	int k,ans=0,tmp;
	scanf("%d", &k);
	while (scanf("%c", &s) != EOF)
	{
		if (s >= '0'&&s <= '9')
		{
			k -= s - '0';
			cnt[s - '0']++;
		}
	}
	if (k <= 0)
		printf("0");
	else
	{
		for (int i = 0; i < 9; i++)
		{
			while (cnt[i])
			{
				if (k - (9 - i) < 0)
					break;
				k -= (9 - i);
				ans++;
				cnt[i]--;
				if (k == 0)
					break;
			}
			/*tmp = k / (9 - i);//����ö��ٸ�
			if (tmp >= cnt[i])
			{
				k -= cnt[i] * (9 - i);
				ans += cnt[i];
			}
			else
			{
				k -= tmp * (9 - i);
				ans += tmp;
				if (k)
					ans++;
			}*/
		}
		printf("%d", ans);
	}
		//printf("%d",k);
}


#include<cstdio>
char s;
int cnt[10];
int main()
{
	int k,ans=0,tmp;
	scanf("%d", &k);
	while (scanf("%c", &s) != EOF)
	{
		if (s >= '0'&&s <= '9')
		{
			k -= s - '0';
			cnt[s - '0']++;
		}
	}
	if (k <= 0)
		printf("0");
	else
	{
		for (int i = 0; i < 9; i++)
		{
			tmp = k / (9 - i);//����ö��ٸ�
			if (tmp >= cnt[i])
			{
				k -= cnt[i] * (9 - i);
				ans += cnt[i];
			}
			else
			{
				k -= tmp * (9 - i);
				ans += tmp;
				if (k)
					ans++;
			}
		}
		printf("%d", ans);
	}
		//printf("%d",k);
}


#include<cstdio>
char s;
int main()
{
	int k;
	scanf("%d", &k);
	while (scanf("%c", &s) != EOF)
	{
		if(s>='0'&&s<='9')
		k -= s - '0';
	}
	if (k <= 0)
		printf("0");
	else
		printf("%d",k);
}


#include<cstdio>
char s;
int cnt[10];
int main()
{
	int k,ans=0,tmp;
	scanf("%d", &k);
	while (scanf("%c", &s) != EOF)
	{
		if (s >= '0'&&s <= '9')
		{
			k -= s - '0';
			cnt[s - '0']++;
		}
	}
	if (k <= 0)
		printf("0");
	else
	{
		for (int i = 0; i < 10; i++)
		{
			tmp = k / (9 - i);
			if (tmp > cnt[i])
			{
				k -= cnt[i] * (9 - i);
				ans += cnt[i];
			}
			else
			{
				k -= tmp * (9 - i);
				ans += tmp;
			}
		}
		printf("%d", ans);
	}
		//printf("%d",k);
}


//
//  main.cpp
//  Codeforces_835B
//
//  Created by Nguyễn Trí on 8/27/18.
//  Copyright © 2018 Nguyễn Trí. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int MinimumOfTime(long k, unsigned long long n) {

    vector <int> digit;
    unsigned long long sum = 0;

    while (n != 0) {
        digit.push_back(n % 10);
        sum += n % 10;
        n /= 10;
    }

    if (sum >= k) return 0;
    sort(digit.begin(),digit.end());

    for (int i = 0; i < digit.size(); ++i) {
        if (sum > k) return i + 1;
        if (digit[i] == 9) return 0;
        sum += 9 - digit[i];
    }

    return 0;
}

int main(int argc, const char * argv[]) {

    long k; cin >> k;
    unsigned long long n; cin >> n;

    cout << MinimumOfTime(k,n) << endl;
    return 0;
}


//
//

#include <iostream>
#include <math.h>
using namespace std;

int Min(int x,int & y);
int Sum(int x);

int main(){
	int k, sum = 0, p = 0;
	long n;
	cin >> k >> n;
	int m;
	sum = Sum(n);
	while (sum < k){
		n = n - Min(n,m)*pow(10, m) + 9 * pow(10, m);
		sum = Sum(n);
		p++;
	}
	cout << p << endl;
}

int Min(int x,int & n){
	n = 0;
	int min = x % 10;
	while (x != 0){
		x /= 10;
		if (x % 10 < min) min = x % 10;
		n++;
	}
	return min;
}

int Sum(int x){
	int sum = 0;
	while (x != 0){
		sum += x % 10;
		x /= 10;
	}
	return sum;

}


//
//  main.cpp
//  Codeforces_835B
//
//  Created by Nguyễn Trí on 8/27/18.
//  Copyright © 2018 Nguyễn Trí. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int MinimumOfTime(long k, string n) {

    vector <int> digit;
    unsigned long long sum = 0;

    for (int i = 0; i < n.size(); ++i) {
        digit.push_back(n[i] - '0');
        sum += n[i] - '0';
    }

    sort(digit.begin(),digit.end());
    for (int i = 0; i <= digit.size(); ++i) {
        if (sum >= k) return i;
        if (i == digit.size() || digit[i] == 9) return 0;
        sum += 9 - digit[i];
    }

    return 0;
}

int main(int argc, const char * argv[]) {

    long k; cin >> k;
    string n; cin >> n;

    cout << MinimumOfTime(k,n) << endl;
    return 0;
}


//
//  main.cpp
//  Codeforces_835B
//
//  Created by Nguyễn Trí on 8/27/18.
//  Copyright © 2018 Nguyễn Trí. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int MinimumOfTime(long k, unsigned long long n) {

    vector <int> digit;
    unsigned long long sum = 0;

    while (n != 0) {
        digit.push_back(n % 10);
        sum += n % 10;
        n /= 10;
    }

    sort(digit.begin(),digit.end());
    for (int i = 0; i <= digit.size(); ++i) {
        if (sum >= k) return i;
        if (i == digit.size() || digit[i] == 9) return 0;
        sum += 9 - digit[i];
    }

    return 0;
}

int main(int argc, const char * argv[]) {

    long k; cin >> k;
    unsigned long long n; cin >> n;

    cout << MinimumOfTime(k,n) << endl;
    return 0;
}


//
//  main.cpp
//  Codeforces_835B
//
//  Created by Nguyễn Trí on 8/27/18.
//  Copyright © 2018 Nguyễn Trí. All rights reserved.
//

#include <iostream>
#include <vector>
using namespace std;

int MinimumOfTime(long k, unsigned long long n) {

    vector <int> digit;
    unsigned long long sum = 0;

    while (n != 0) {
        digit.push_back(n % 10);
        sum += n % 10;
        n /= 10;
    }

    if (sum >= k) return 0;
    sort(digit.begin(),digit.end());

    for (int i = 0; i < digit.size(); ++i) {
        if (sum > k) return i + 1;
        if (digit[i] == 9) return 0;
        sum += 9 - digit[i];
    }

    return 0;
}

int main(int argc, const char * argv[]) {

    long k; cin >> k;
    unsigned long long n; cin >> n;

    cout << MinimumOfTime(k,n) << endl;

    // insert code here...
    std::cout << "Hello, World!\n";
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<cmath>
#include<ctime>
#include<queue>
#include<map>
#define rint register int
#define debug(x) cerr<<#x<<"="<<x<<endl
#define fgx cerr<<"-------------"<<endl
typedef long long ll;
using namespace std;
int num[100];
char c[100001];
int main()
{	ll n,ans=0,sum=0;
	cin>>n; scanf("%s",c+1); int len=strlen(c+1);
	for(rint i=1;i<=len;i++)
	{	char ch=c[i];
		num[ch-'0']++;
		sum+=ch-'0';
	}
	if(sum>=n) {cout<<0<<endl;return 0;}
	int now=0;
	while(sum<n)
	{	if(sum+1LL*(9-now)*num[now]>=n)
		{	cout<<ans+ceil(1.0*(n-sum)/(9-now))<<endl;
			return 0;
		}
		sum+=1LL*(9-now)*num[now]; now++;
	}
 	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<cmath>
#include<ctime>
#include<queue>
#include<map>
#define rint register int
#define debug(x) cerr<<#x<<"="<<x<<endl
#define fgx cerr<<"-------------"<<endl
typedef long long ll;
using namespace std;
int num[100];
char c[100001];
int main()
{	ll n,ans=0,sum=0;
	cin>>n; scanf("%s",c+1); int len=strlen(c+1);
	for(rint i=1;i<=len;i++)
	{	char ch=c[i];
		num[ch-'0']++;
		sum+=ch-'0';
	}
	if(sum>=n) {cout<<0<<endl;return 0;}
	int now=0;
	while(sum<n)
	{	if(sum+1LL*(9-now)*num[now]>=n) {cout<<ans+ceil(1.0*(n-sum)/(9-now))<<endl;return 0;}
		sum+=(9-now)*num[now]; now++;
	}
 	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<cmath>
#include<ctime>
#include<queue>
#include<map>
#define rint register int
#define debug(x) cerr<<#x<<"="<<x<<endl
#define fgx cerr<<"-------------"<<endl
typedef long long ll;
using namespace std;
int num[100];
char c[100001];
int main()
{	ll n,ans=0,sum=0;
	cin>>n; scanf("%s",c+1); int len=strlen(c+1);
	for(rint i=1;i<=len;i++)
	{	char ch=c[i];
		num[ch-'0']++;
		sum+=ch-'0';
	}
	if(sum>=n) {cout<<0<<endl;return 0;}
	int now=0;
	while(sum<n)
	{	if(sum+1LL*(9-now)*num[now]>=n)
		{	cout<<ans+ceil(1.0*(n-sum)/(9-now))<<endl;
			return 0;
		}
		sum+=1LL*(9-now)*num[now]; ans+=num[now];now++;
	}
 	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<cmath>
#include<ctime>
#include<queue>
#include<map>
#define rint register int
#define debug(x) cerr<<#x<<"="<<x<<endl
#define fgx cerr<<"-------------"<<endl
typedef long long ll;
using namespace std;
int num[100];
char c[100001];
int main()
{	int n,ans=0,sum=0;
	cin>>n; scanf("%s",c+1); int len=strlen(c+1);
	for(rint i=1;i<=len;i++)
	{	char ch=c[i];
		num[ch-'0']++;
		sum+=ch-'0';
	}
	if(sum>=n) {cout<<0<<endl;return 0;}
	int now=0;
	while(sum<n)
	{	debug(sum);
		if(sum+1LL*(9-now)*num[now]>=n) {cout<<ans+ceil(1.0*(n-sum)/(9-now))<<endl;return 0;}
		sum+=(9-8)*num[now]; now++;
	}
 	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<cmath>
#include<ctime>
#include<queue>
#include<map>
#define rint register int
#define debug(x) cerr<<#x<<"="<<x<<endl
#define fgx cerr<<"-------------"<<endl
typedef long long ll;
using namespace std;
int num[100];
char c[100001];
int main()
{	ll n,ans=0,sum=0;
	cin>>n; scanf("%s",c+1); int len=strlen(c+1);
	for(rint i=1;i<=len;i++)
	{	char ch=c[i];
		num[ch-'0']++;
		sum+=ch-'0';
	}
	if(sum>=n) {cout<<0<<endl;return 0;}
	int now=0;
	while(sum<n)
	{	if(sum+1LL*(9-now)*num[now]>=n) {cout<<ans+ceil(1.0*(n-sum)/(9-now))<<endl;return 0;}
		sum+=(9-8)*num[now]; now++;
	}
 	return 0;
}


#include<cstdio>
#include<iostream>
#include<map>
#include<cstring>
#include<algorithm>
using namespace std;

char s[1000005];
long long a[1000005];

int main(){
	long long k,sum = 0,ans = 0;
	cin >> k;
	cin >> s + 1;
	long long len = strlen(s + 1);
	for(int i = 1;i <= len;i++){
		sum += s[i] - '0';
		a[i] = 9 - (s[i] - '0');
	}
	if(sum >= k) cout << "0";
	else{
		long long tot = k - sum;
		for(int i = 1;i <= len;i++){
			tot -= a[i];
			ans++;
			if(tot <= 0) break;
		}
		cout << ans;
	}
}


#include<cstdio>
#include<iostream>
#include<map>
#include<cstring>
#include<algorithm>
using namespace std;

char s[1000005];
long long a[1000005];

int main(){
	long long k,sum = 0,ans = 0;
	cin >> k;
	cin >> s + 1;
	long long len = strlen(s + 1);
	for(int i = 1;i <= len;i++){
		sum += s[i] - '0';
		a[i] = 9 - (s[i] - '0');
	}
	if(sum >= k) cout << "0";
	else{
		long long tot = k - sum;
		for(int i = 1;i <= len;i++){
			if(a[i] == 0) continue;
			tot -= a[i];
			ans++;
			if(tot <= 0) break;
		}
		cout << ans;
	}
}


#include<cstdio>
#include<iostream>
#include<map>
#include<cstring>
#include<algorithm>
using namespace std;

char s[1000005];
long long a[1000005];

int main(){
	long long k,sum = 0,ans = 0;
	cin >> k;
	cin >> s + 1;
	long long len = strlen(s + 1);
	sort(s + 1,s + 1 + len);
	for(int i = 1;i <= len;i++){
		sum += s[i] - '0';
		a[i] = 9 - (s[i] - '0');
	}
	if(sum >= k) cout << "0";
	else{
		long long tot = k - sum;
		for(int i = 1;i <= len;i++){
			if(a[i] == 0) continue;
			tot -= a[i];
			ans++;
			if(tot <= 0) break;
		}
		cout << ans;
	}
}


#include<cstdio>
#include<iostream>
#include<map>
#include<cstring>
#include<algorithm>
using namespace std;

char s[1000005];
long long a[1000005];

int main(){
	long long k,sum = 0,ans = 0;
	cin >> k;
	cin >> s + 1;
	long long len = strlen(s + 1);
	for(int i = 1;i <= len;i++){
		sum += s[i] - '0';
		a[i] = 9 - (s[i] - '0');
	}
	if(sum >= k) cout << "0";
	else{
		long long tot = k - sum;
		for(int i = len;i >= 1;i--){
			if(a[i] == 0) continue;
			ans = len - i + 1;
			break;
		}
		cout << ans;
	}
}


#include<cstdio>
#include<iostream>
#include<map>
#include<cstring>
#include<algorithm>
using namespace std;

char s[1000005];
long long a[1000005];

int main(){
	long long k,sum = 0,ans = 0;
	cin >> k;
	cin >> s + 1;
	long long len = strlen(s + 1);
	for(int i = 1;i <= len;i++){
		sum += s[i] - '0';
		a[i] = 9 - (s[i] - '0');
	}
	if(sum >= k) cout << "0";
	else{
		long long tot = k - sum;
		for(int i = len;i >= 1;i--){
			if(a[i] == 0) continue;
			tot -= a[i];
			ans = len - i + 1;
			if(tot <= 0) break;
		}
		cout << ans;
	}
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
string n;
ll k;
int main()
{
	cin>>k>>n;
	ll cnt[10],temp,sum=0,dig=0;
	for(ll i=0;i<10;i++)
	cnt[i]=0;
	for(ll i=0;i<ll (n.size());i++)
	{
		temp=n[i]-'0';
		cnt[temp]++;
		sum+=temp;
	}
	for(ll i=0;i<10;i++)
	{
		while(cnt[i]>0)
		{
			if(sum<k)
			{
			sum+=9-i;
			dig++;
			cnt[i]--;
		    }
		    else
		    break;
		}
		if(sum>=k)
		break;
	}
	cout<<dig<<endl;
}


#include<iostream> #include<algorithm> using namespace std; typedef long long ll; int main() { 	ll n,k,arr[1000000],arrd[1000000]; 	cin>>k>>n; 	ll temp=n,sum=0,i=0,dig=0,vali=0; 	while(temp>0) 	{ 		sum+=temp%10; 		arr[i++]=temp%10; 		temp=temp/10; 	} 	sort(arr,arr+i); 	//cout<<"sum"<<sum<<"count"<<i<<endl; 	if(sum>=k) 	cout<<0<<endl; 	else 	{ 		for(ll j=0;j<i;j++) 		{ 			sum+=9-arr[j]; 			dig++; 			if(sum>=k) 			break; 			if(dig==i) 			break; 			//cout<<"i+1 "<<i+1<<endl; 		} 		cout<<dig<<endl; 	} }


#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
int main()
{
	ll n,k,arr[100],arrd[100];
	cin>>k>>n;
	ll temp=n,sum=0,i=0,dig=0,vali=0;
	while(temp>0)
	{
		sum+=temp%10;
		arr[i++]=temp%10;
		temp=temp/10;
	}
	sort(arr,arr+i);
	//cout<<"sum"<<sum<<"count"<<i<<endl;
	if(sum>=k)
	cout<<0<<endl;
	else
	{
		for(ll j=0;j<i;j++)
		{
			sum+=9-arr[j];
			dig++;
			if(sum>=k)
			break;
			if(dig==i)
			break;
			//cout<<"i+1 "<<i+1<<endl;
		}
		cout<<dig<<endl;
	}
}


#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
int main()
{
	ll n,k,arr[10],arrd[10];
	cin>>k>>n;
	ll temp=n,sum=0,i=0,dig=0,vali=0;
	while(temp>0)
	{
		sum+=temp%10;
		arr[i++]=temp%10;
		temp=temp/10;
	}
	sort(arr,arr+i);
	//cout<<"sum"<<sum<<"count"<<i<<endl;
	if(sum>=k)
	cout<<0<<endl;
	else
	{
		for(ll j=0;j<i;j++)
		{
			if(sum>=k)
			break;
			sum+=9-arr[j];
			dig++;
			//cout<<"i+1 "<<i+1<<endl;
		}
		cout<<dig<<endl;
	}
}


#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
int main()
{
	ll n,k,arr[10],arrd[10];
	cin>>k>>n;
	ll temp=n,sum=0,i=0,dig=0,vali=0;
	while(temp>0)
	{
		sum+=temp%10;
		arr[i++]=temp%10;
		temp=temp/10;
	}
	sort(arr,arr+i);
	//cout<<"sum"<<sum<<"count"<<i<<endl;
	if(sum>=k)
	cout<<0<<endl;
	else
	{
		for(ll j=0;j<i;j++)
		{
			if(sum>=k)
			break;
			sum+=9-arr[j];
			dig++;
			if(dig==i)
			break;
			//cout<<"i+1 "<<i+1<<endl;
		}
		cout<<dig<<endl;
	}
}


#include<iostream>
#include<algorithm>
 using namespace std;
  typedef long long ll; int main() { 	ll n,k,arr[1000000],dig=0;	cin>>k>>n; 	ll temp=n,sum=0,i=0,vali=0; 	while(temp>0) 	{ 		sum+=temp%10; 		arr[i++]=temp%10; 		temp=temp/10; 	} 	sort(arr,arr+i); 		if(sum>=k) 	cout<<0<<endl; 	else 	{ 		for(ll j=0;j<i;j++) 		{ 			sum+=9-arr[j]; 			dig++; 			if(sum>=k) 			break; 			if(dig==i) 			break; 					} 		cout<<dig<<endl; 	} }


#include<iostream>
using namespace std;
typedef long long ll;
int main()
{
	ll n,k,arr[10],arrd[10];
	cin>>k>>n;
	ll temp=n,sum=0,i=0,dig=0,vali=0;
	while(temp>0)
	{
		sum+=temp%10;
		arr[i++]=temp%10;
		temp=temp/10;
	}
	if(sum>=k)
	cout<<0<<endl;
	else
	{
		for(ll j=0;j<i;j++)
		{
			if(sum>=k)
			break;
			sum+=9-arr[j];
			dig++;
			//cout<<"i+1 "<<i+1<<endl;
			if(dig>i)
			{
				dig-=1;
				break;
			}
		}
		cout<<dig<<endl;
	}
}


#include<iostream>
using namespace std;
typedef long long ll;
int main()
{
	ll n,k,arr[10],arrd[10];
	cin>>k>>n;
	ll temp=n,sum=0,i=0,dig=0,vali=0;
	while(temp>0)
	{
		sum+=temp%10;
		arr[i++]=temp%10;
		temp=temp/10;
	}
	if(sum>=k)
	cout<<0<<endl;
	else
	{
		for(ll j=0;j<i;j++)
		{
			sum+=9-arr[j];
			arr[j]=9;
			dig++;
			//cout<<"i+1 "<<i+1<<endl;
			if(dig>i)
			{
				dig-=1;
				break;
			}
			if(sum>=k)
			break;
		}
		cout<<dig<<endl;
	}
}


#include<iostream>
using namespace std;
typedef long long ll;
int main()
{
  ll sum=0,n,k,temp,arr[10],dig=0;
  cin>>k>>n;
  temp=n;
  for(ll i=0;i<=9;i++)
  arr[i]=0;
  while(temp>0)
  {
    sum+=temp%10;
    arr[temp%10]++;
    temp/=10;
  }

  for(ll i=0;i<=10;i++)
  {
    if(arr[i]>0)
    {
      sum+=9-i;
      i--;
      arr[i]--;
      dig++;
     }
    if(sum>=k)
    break;
  }
  cout<<dig<<endl;
}


#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int num[9] = {0};

int main(){
    int kol, k, sum;
    long int n;

    cin >> k >> n;

    sum = 0;

    while (n!=0){
        int j = n%10;
        sum += j;
        if (j!=9){
            num[j]++;
        }
        n /= 10;
    }

    kol = 0;

    while (k>sum){
        if (num[0]!=0){ sum += 9; num[0]--; kol++; continue;};
        if (num[1]!=0){ sum += 8; num[1]--; kol++; continue;};
        if (num[2]!=0){ sum += 7; num[2]--; kol++; continue;};
        if (num[3]!=0){ sum += 6; num[3]--; kol++; continue;};
        if (num[4]!=0){ sum += 5; num[4]--; kol++; continue;};
        if (num[5]!=0){ sum += 4; num[5]--; kol++; continue;};
        if (num[6]!=0){ sum += 3; num[6]--; kol++; continue;};
        if (num[7]!=0){ sum += 2; num[7]--; kol++; continue;};
        if (num[8]!=0){ sum += 1; num[8]--; kol++; continue;};
    }

    cout << kol;

    return 0;
}


#include <fstream>
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(){
    ifstream fin("input.txt");
    //ofstream fout("output.txt");

    int num[9], kol, k, sum, n;

    fin >> k >> n;

    sum = 0;

    while (n!=0){
        sum += n%10;
        switch (n%10){
            case 1: num[1]++; break;
            case 2: num[2]++; break;
            case 3: num[3]++; break;
            case 4: num[4]++; break;
            case 5: num[5]++; break;
            case 6: num[6]++; break;
            case 7: num[7]++; break;
            case 8: num[8]++; break;
            case 0: num[0]++; break;
        }
        n /= 10;
    }

    kol = 0;

    while (k>sum){
        if (num[0]!=0){ sum += 9; num[0]--; kol++; continue;};
        if (num[1]!=0){ sum += 8; num[1]--; kol++; continue;};
        if (num[2]!=0){ sum += 7; num[2]--; kol++; continue;};
        if (num[3]!=0){ sum += 6; num[3]--; kol++; continue;};
        if (num[4]!=0){ sum += 5; num[4]--; kol++; continue;};
        if (num[5]!=0){ sum += 4; num[5]--; kol++; continue;};
        if (num[6]!=0){ sum += 3; num[6]--; kol++; continue;};
        if (num[7]!=0){ sum += 2; num[7]--; kol++; continue;};
        if (num[8]!=0){ sum += 1; num[8]--; kol++; continue;};
    }

    cout << kol;

    fin.close();
    //fout.close();
    return 0;
}


#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int num[9] = {0};

int main(){
    int kol, k, kos, sum;
    string n;

    cin >> k >> n;

    sum = 0; kos = 0;

    for (int i = 0; i < n.length(); i++){
        sum+=n[i]-'0';
        num[n[i]-'0']++;
        kos++;
    }

    kol = 0;

    while ((k>sum) && (kos>0)){
        if (num[0]!=0){ sum += 9; num[0]--; kol++; kos--; continue;};
        if (num[1]!=0){ sum += 8; num[1]--; kol++; kos--; continue;};
        if (num[2]!=0){ sum += 7; num[2]--; kol++; kos--; continue;};
        if (num[3]!=0){ sum += 6; num[3]--; kol++; kos--; continue;};
        if (num[4]!=0){ sum += 5; num[4]--; kol++; kos--; continue;};
        if (num[5]!=0){ sum += 4; num[5]--; kol++; kos--; continue;};
        if (num[6]!=0){ sum += 3; num[6]--; kol++; kos--; continue;};
        if (num[7]!=0){ sum += 2; num[7]--; kol++; kos--; continue;};
        if (num[8]!=0){ sum += 1; num[8]--; kol++; kos--; continue;};
    }

    cout << kol;

    return 0;
}


#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(){
    int num[9], kol, k, sum, n;

    cin >> k >> n;

    sum = 0;

    while (n!=0){
        sum += n%10;
        switch (n%10){
            case 1: num[1]++; break;
            case 2: num[2]++; break;
            case 3: num[3]++; break;
            case 4: num[4]++; break;
            case 5: num[5]++; break;
            case 6: num[6]++; break;
            case 7: num[7]++; break;
            case 8: num[8]++; break;
            case 0: num[0]++; break;
        }
        n /= 10;
    }

    kol = 0;

    while (k>sum){
        if (num[0]!=0){ sum += 9; num[0]--; kol++; continue;};
        if (num[1]!=0){ sum += 8; num[1]--; kol++; continue;};
        if (num[2]!=0){ sum += 7; num[2]--; kol++; continue;};
        if (num[3]!=0){ sum += 6; num[3]--; kol++; continue;};
        if (num[4]!=0){ sum += 5; num[4]--; kol++; continue;};
        if (num[5]!=0){ sum += 4; num[5]--; kol++; continue;};
        if (num[6]!=0){ sum += 3; num[6]--; kol++; continue;};
        if (num[7]!=0){ sum += 2; num[7]--; kol++; continue;};
        if (num[8]!=0){ sum += 1; num[8]--; kol++; continue;};
    }

    cout << kol;

    return 0;
}


#include <bits/stdc++.h>
#include <vector>
#include <queue>

#define ll long long

using namespace std;

int main()
{
	ll k,n,i,j;
	cin>>k>>n;
	ll len,temp=n;
	ll rem=0;
	vector<ll> digits;
	while(temp>0)
	{
		rem=temp%10;
		temp=temp/10;
		digits.push_back(rem);
	}
	ll sum=0;
	for(i=0;i<digits.size();i++)
		sum+=digits[i];
	if(sum>=k)
	{
		cout<<0;
		return 0;
	}
	ll ans=0;
	temp=1000000000;
	for(i=0;i<digits.size();i++)
	{
		temp=min_element(digits.begin(),digits.end())-digits.begin();
		digits[temp]=9;
		for(j=0;j<digits.size();j++)
			ans+=digits[j];
		if(ans>=k)
		{
			cout<<i+1;
			return 0;
		}
		ans=0;
	}
	return 0;
}


#include <bits/stdc++.h>
#include <vector>
#include <queue>

#define ll long long

using namespace std;

vector<ll> digits;

int main()
{
	ll k,n,i,j;
	cin>>k>>n;
	ll temp=n;
	ll rem;
	digits.clear();
	while(temp>0)
	{
		rem=temp%10;
		temp=temp/10;
		digits.push_back(rem);
	}
	ll sum=0;
	for(i=0;i<digits.size();i++)
		sum+=digits[i];
	if(sum>=k)
	{
		cout<<0;
		return 0;
	}
	ll ans=0;
//	for(i=0;i<digits.size();i++)
//		cout<<digits[i];
//	cout<<endl;
	sort(digits.begin(),digits.end());
	for(j=0;j<digits.size();j++)
			ans+=digits[j];
	for(i=0;i<digits.size();i++)
	{
		ans=ans+9-digits[i];
//		for(j=0;j<digits.size();j++)
//			cout<<digits[j];
		if(ans>=k)
		{
			cout<<i+1;
			return 0;
		}
	}
	return 0;
}