import java.io.*;
import java.nio.CharBuffer;
import java.util.NoSuchElementException;

public class P1195B {

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

        int n = scanner.nextInt();
        int k = scanner.nextInt();
        int l = 0;
        int r = n;
        int ans = 0;
        while (l <= r) {
            int eat = (l + r) >> 1;
            int lastPut = n - eat;
            long totalPut = (long) (lastPut + 1) * lastPut / 2;
            long remain = totalPut - eat;
            if (remain == k) {
                ans = eat;
                break;
            } else if (remain > k)
                l = eat + 1;
            else
                r = eat - 1;
        }
        writer.println(ans);

        writer.close();
    }

    private static class SimpleScanner {

        private static final int BUFFER_SIZE = 10240;

        private Readable in;
        private CharBuffer buffer;
        private boolean eof;

        SimpleScanner(InputStream in) {
            this.in = new BufferedReader(new InputStreamReader(in));
            buffer = CharBuffer.allocate(BUFFER_SIZE);
            buffer.limit(0);
            eof = false;
        }

        private char read() {
            if (!buffer.hasRemaining()) {
                buffer.clear();
                int n;
                try {
                    n = in.read(buffer);
                } catch (IOException e) {
                    n = -1;
                }
                if (n <= 0) {
                    eof = true;
                    return '\0';
                }
                buffer.flip();
            }
            return buffer.get();
        }

        void checkEof() {
            if (eof)
                throw new NoSuchElementException();
        }

        char nextChar() {
            checkEof();
            char b = read();
            checkEof();
            return b;
        }

        String next() {
            char b;
            do {
                b = read();
                checkEof();
            } while (Character.isWhitespace(b));
            StringBuilder sb = new StringBuilder();
            do {
                sb.append(b);
                b = read();
            } while (!eof && !Character.isWhitespace(b));
            return sb.toString();
        }

        int nextInt() {
            return Integer.valueOf(next());
        }

        long nextLong() {
            return Long.valueOf(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}


import java.util.Scanner;

public class CodeForces {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
	int k = sc.nextInt();
        int ans = 0;
        long x = n;
        x = x*(x+1)/2;
        while (x!=k) {
            x-=n;
            n--;
            ans++;
            k++;
        }
        System.out.println(ans);
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.*;
import java.util.concurrent.ThreadLocalRandom;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main2 {

    static int mod = 1000000007;
    static FastScanner scanner;

    public static void main(String[] args) {
        scanner = new FastScanner();
        long n = scanner.nextInt();
        long k = scanner.nextInt();

        if (sum(n) == k) {
            System.out.println(0);
            return;
        }

        long s = 0;
        long e = n + 1;
        while (s < e - 1) {
            long m = (s + e) / 2;
            long put = sum(n - m);
            long candiesLeft = put - m;
            if (candiesLeft == k) {
                System.out.println(m);
                return;
            }
            if (candiesLeft > k) {
                s = m;
            } else {
                e = m;
            }
        }
    }

    static long sum(long n) {
        long last = 1 + n - 1;
        return ((1 + last) * n) / 2;
    }

    static class WithIdx {
        int val, idx;

        public WithIdx(int val, int idx) {
            this.val = val;
            this.idx = idx;
        }
    }

    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String nextToken() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        String nextLine() {
            try {
                return br.readLine();
            } catch (Exception e) {
                e.printStackTrace();
                throw new RuntimeException();
            }
        }

        int nextInt() {
            return Integer.parseInt(nextToken());
        }

        long nextLong() {
            return Long.parseLong(nextToken());
        }

        double nextDouble() {
            return Double.parseDouble(nextToken());
        }

        int[] nextIntArray(int n) {
            int[] res = new int[n];
            for (int i = 0; i < n; i++) res[i] = nextInt();
            return res;
        }

        long[] nextLongArray(int n) {
            long[] res = new long[n];
            for (int i = 0; i < n; i++) res[i] = nextLong();
            return res;
        }

        String[] nextStringArray(int n) {
            String[] res = new String[n];
            for (int i = 0; i < n; i++) res[i] = nextToken();
            return res;
        }
    }

    static class PrefixSums {
        long[] sums;

        public PrefixSums(long[] sums) {
            this.sums = sums;
        }

        public long sum(int fromInclusive, int toExclusive) {
            if (fromInclusive > toExclusive) throw new IllegalArgumentException("Wrong value");
            return sums[toExclusive] - sums[fromInclusive];
        }

        public static PrefixSums of(int[] ar) {
            long[] sums = new long[ar.length + 1];
            for (int i = 1; i <= ar.length; i++) {
                sums[i] = sums[i - 1] + ar[i - 1];
            }
            return new PrefixSums(sums);
        }

        public static PrefixSums of(long[] ar) {
            long[] sums = new long[ar.length + 1];
            for (int i = 1; i <= ar.length; i++) {
                sums[i] = sums[i - 1] + ar[i - 1];
            }
            return new PrefixSums(sums);
        }
    }

    static class ADUtils {
        static void sort(int[] ar) {
            Random rnd = ThreadLocalRandom.current();
            for (int i = ar.length - 1; i > 0; i--)
            {
                int index = rnd.nextInt(i + 1);
                // Simple swap
                int a = ar[index];
                ar[index] = ar[i];
                ar[i] = a;
            }
            Arrays.sort(ar);
        }

        static void reverse(int[] arr) {
            int last = arr.length / 2;
            for (int i = 0; i < last; i++) {
                int tmp = arr[i];
                arr[i] = arr[arr.length - 1 - i];
                arr[arr.length - 1 - i] = tmp;
            }
        }

        static void sort(long[] ar) {
            Random rnd = ThreadLocalRandom.current();
            for (int i = ar.length - 1; i > 0; i--)
            {
                int index = rnd.nextInt(i + 1);
                // Simple swap
                long a = ar[index];
                ar[index] = ar[i];
                ar[i] = a;
            }
            Arrays.sort(ar);
        }
    }

    static class MathUtils {
        static long[] FIRST_PRIMES = {
                2,     3,      5,      7,     11,     13,     17,     19,     23,     29,
                31,     37,     41,     43,     47,     53,     59,     61,     67,     71,
                73,     79,     83,     89  ,   97 ,    101,    103,    107,    109,    113,
                127,    131,    137,    139,    149,    151,    157,    163,    167,    173,
                179,    181,    191,    193,    197,    199,    211,    223,    227,    229,
                233,    239,    241,    251,    257,    263,    269,    271,    277,    281,
                283,    293,    307,    311,    313,    317,    331,    337,    347,    349,
                353,    359,    367,    373,    379,    383,    389,    397,    401,    409,
                419,    421,    431,    433,    439,    443,    449,    457,    461,    463,
                467,    479,    487,    491,    499,    503,    509,    521,    523,    541,
                547,    557,    563,    569,    571,    577,    587,    593,    599,    601,
                607,    613,    617,    619,    631,    641,    643,    647,    653,    659,
                661,    673,    677,    683,    691,    701,    709,    719,    727,    733,
                739,    743,    751,    757,    761,    769,    773,    787,    797,    809,
                811,    821,    823,    827,    829,    839,    853,    857,    859,    863,
                877,    881,    883,    887,    907,    911,    919,    929,    937,    941,
                947,    953,    967,    971,    977,    983,    991,    997,   1009,   1013,
                1019,   1021,   1031,   1033,   1039,   1049,   1051};

        static long[] primes(int to) {
            long[] all = new long[to + 1];
            long[] primes = new long[to + 1];
            all[1] = 1;
            int primesLength = 0;
            for (int i = 2; i <= to; i ++) {
                if (all[i] == 0) {
                    primes[primesLength++] = i;
                    all[i] = i;
                }
                for (int j = 0; j < primesLength && i * primes[j] <= to && all[i] >= primes[j]; j++) {
                    all[(int) (i * primes[j])] = primes[j];
                }
            }
            return Arrays.copyOf(primes, primesLength);
        }

        static long modpow(long b, long e, long m) {
            long result = 1;

            while (e > 0) {
                if ((e & 1) == 1) {
                    /* multiply in this bit's contribution while using modulus to keep
                     * result small */
                    result = (result * b) % m;
                }
                b = (b * b) % m;
                e >>= 1;
            }

            return result;
        }

        static long submod(long x, long y, long m) {
            return (x - y + m) % m;
        }
    }
}


/*
Roses are red
Memes are neat
All my test cases time out
Lmao yeet
*/
import java.util.*;
import java.io.*;

   public class B
   {
      public static void main(String args[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         int K = Integer.parseInt(st.nextToken());
         //bin search
         //ugh I'm shafting
         long x = (long)N;
         long low = 0L;
         long high = N;
         while(low != high)
         {
            x = (low+high+1)/2;
            long add = (x*(x+1))/2;
            long y = N-x;
            if(add-y > K)
               high = x;
            else if(add-y == K)
            {
               System.out.println(y);
               break;
            }
            else
               low = x;
         }
         //run time?
      }
      public static void sort(int[] arr)
      {
         PriorityQueue<Integer> pq = new PriorityQueue<Integer>();
         for(int a: arr)
            pq.add(a);
         for(int i=0; i < arr.length; i++)
            arr[i] = pq.poll();
      }
   }


    import java.util.*;
    import java.io.*;
    import java.lang.*;
    import java.math.*;
    public class D {
        public static void main(String[] args) throws Exception {
            BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
            PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
            // int n = Integer.parseInt(bf.readLine());
            StringTokenizer st = new StringTokenizer(bf.readLine());
            int n = Integer.parseInt(st.nextToken());
            int k = Integer.parseInt(st.nextToken());

            for(int i=0; i<100000; i++) {
              long mult = 1L*i*(i+1)/2;
              long b = 1L*mult - k;
              if(i+b == n*1L) {
                out.println(b);
                out.close(); System.exit(0);
              }
            }
            //out.println(count);
            out.close(); System.exit(0);
        }
    }

    // a(a+1)/2 - b = k;   a+b = n


import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;

public class CFContest {
    public static void main(String[] args) throws Exception {
        boolean local = System.getProperty("ONLINE_JUDGE") == null;
        boolean async = false;

        Charset charset = Charset.forName("ascii");

        FastIO io = local ? new FastIO(new FileInputStream("D:\\DATABASE\\TESTCASE\\Code.in"), System.out, charset) : new FastIO(System.in, System.out, charset);
        Task task = new Task(io, new Debug(local));

        if (async) {
            Thread t = new Thread(null, task, "dalt", 1 << 27);
            t.setPriority(Thread.MAX_PRIORITY);
            t.start();
            t.join();
        } else {
            task.run();
        }

        if (local) {
            io.cache.append("\n\n--memory -- \n" + ((Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) >> 20) + "M");
        }

        io.flush();
    }

    public static class Task implements Runnable {
        final FastIO io;
        final Debug debug;
        int inf = (int) 1e8;

        public Task(FastIO io, Debug debug) {
            this.io = io;
            this.debug = debug;
        }

        @Override
        public void run() {
            solve();
        }

        public void solve() {
            int n = io.readInt();
            int k = io.readInt();
            int l = 0;
            int r = n;
            while (l < r) {
                int m = (l + r + 1) >> 1;
                if (when(n, m) < k) {
                    r = m - 1;
                } else {
                    l = m;
                }
            }

            io.cache.append(l);
        }

        public long when(int n, int t) {
            long put = n - t;
            return (put + 1) * put / 2 - t;
        }
    }

    public static class FastIO {
        public final StringBuilder cache = new StringBuilder();
        private final InputStream is;
        private final OutputStream os;
        private final Charset charset;
        private StringBuilder defaultStringBuf = new StringBuilder(1 << 8);
        private byte[] buf = new byte[1 << 13];
        private int bufLen;
        private int bufOffset;
        private int next;

        public FastIO(InputStream is, OutputStream os, Charset charset) {
            this.is = is;
            this.os = os;
            this.charset = charset;
        }

        public FastIO(InputStream is, OutputStream os) {
            this(is, os, Charset.forName("ascii"));
        }

        private int read() {
            while (bufLen == bufOffset) {
                bufOffset = 0;
                try {
                    bufLen = is.read(buf);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
                if (bufLen == -1) {
                    return -1;
                }
            }
            return buf[bufOffset++];
        }

        public void skipBlank() {
            while (next >= 0 && next <= 32) {
                next = read();
            }
        }

        public int readInt() {
            int sign = 1;

            skipBlank();
            if (next == '+' || next == '-') {
                sign = next == '+' ? 1 : -1;
                next = read();
            }

            int val = 0;
            if (sign == 1) {
                while (next >= '0' && next <= '9') {
                    val = val * 10 + next - '0';
                    next = read();
                }
            } else {
                while (next >= '0' && next <= '9') {
                    val = val * 10 - next + '0';
                    next = read();
                }
            }

            return val;
        }

        public long readLong() {
            int sign = 1;

            skipBlank();
            if (next == '+' || next == '-') {
                sign = next == '+' ? 1 : -1;
                next = read();
            }

            long val = 0;
            if (sign == 1) {
                while (next >= '0' && next <= '9') {
                    val = val * 10 + next - '0';
                    next = read();
                }
            } else {
                while (next >= '0' && next <= '9') {
                    val = val * 10 - next + '0';
                    next = read();
                }
            }

            return val;
        }

        public double readDouble() {
            boolean sign = true;
            skipBlank();
            if (next == '+' || next == '-') {
                sign = next == '+';
                next = read();
            }

            long val = 0;
            while (next >= '0' && next <= '9') {
                val = val * 10 + next - '0';
                next = read();
            }
            if (next != '.') {
                return sign ? val : -val;
            }
            next = read();
            long radix = 1;
            long point = 0;
            while (next >= '0' && next <= '9') {
                point = point * 10 + next - '0';
                radix = radix * 10;
                next = read();
            }
            double result = val + (double) point / radix;
            return sign ? result : -result;
        }

        public String readString(StringBuilder builder) {
            skipBlank();

            while (next > 32) {
                builder.append((char) next);
                next = read();
            }

            return builder.toString();
        }

        public String readString() {
            defaultStringBuf.setLength(0);
            return readString(defaultStringBuf);
        }

        public int readLine(char[] data, int offset) {
            int originalOffset = offset;
            while (next != -1 && next != '\n') {
                data[offset++] = (char) next;
                next = read();
            }
            return offset - originalOffset;
        }

        public int readString(char[] data, int offset) {
            skipBlank();

            int originalOffset = offset;
            while (next > 32) {
                data[offset++] = (char) next;
                next = read();
            }

            return offset - originalOffset;
        }

        public int readString(byte[] data, int offset) {
            skipBlank();

            int originalOffset = offset;
            while (next > 32) {
                data[offset++] = (byte) next;
                next = read();
            }

            return offset - originalOffset;
        }

        public char readChar() {
            skipBlank();
            char c = (char) next;
            next = read();
            return c;
        }

        public void flush() {
            try {
                os.write(cache.toString().getBytes(charset));
                os.flush();
                cache.setLength(0);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        public boolean hasMore() {
            skipBlank();
            return next != -1;
        }
    }

    public static class Debug {
        private boolean allowDebug;

        public Debug(boolean allowDebug) {
            this.allowDebug = allowDebug;
        }

        public void assertTrue(boolean flag) {
            if (!allowDebug) {
                return;
            }
            if (!flag) {
                fail();
            }
        }

        public void fail() {
            throw new RuntimeException();
        }

        public void assertFalse(boolean flag) {
            if (!allowDebug) {
                return;
            }
            if (flag) {
                fail();
            }
        }

        private void outputName(String name) {
            System.out.print(name + " = ");
        }

        public void debug(String name, int x) {
            if (!allowDebug) {
                return;
            }

            outputName(name);
            System.out.println("" + x);
        }

        public void debug(String name, long x) {
            if (!allowDebug) {
                return;
            }
            outputName(name);
            System.out.println("" + x);
        }

        public void debug(String name, double x) {
            if (!allowDebug) {
                return;
            }
            outputName(name);
            System.out.println("" + x);
        }

        public void debug(String name, int[] x) {
            if (!allowDebug) {
                return;
            }
            outputName(name);
            System.out.println(Arrays.toString(x));
        }

        public void debug(String name, long[] x) {
            if (!allowDebug) {
                return;
            }
            outputName(name);
            System.out.println(Arrays.toString(x));
        }

        public void debug(String name, double[] x) {
            if (!allowDebug) {
                return;
            }
            outputName(name);
            System.out.println(Arrays.toString(x));
        }

        public void debug(String name, Object x) {
            if (!allowDebug) {
                return;
            }
            outputName(name);
            System.out.println("" + x);
        }

        public void debug(String name, Object... x) {
            if (!allowDebug) {
                return;
            }
            outputName(name);
            System.out.println(Arrays.deepToString(x));
        }
    }
}


import java.io.*;
import java.math.BigInteger;
import java.util.*;
import java.lang.*;
import static java.lang.Math.*;

public class Main implements Runnable {
    public static void main(String[] args) {
        new Thread(null, new Main(), "Check2", 1 << 28).start();// to increse stack size in java
    }
    static long mod = (long) (1e9 + 7);
    public void run() {
        InputReader in = new InputReader(System.in);
        PrintWriter w = new PrintWriter(System.out);

        long  n = in.nextLong();
        long k = in.nextLong();
        long ans= 0;
        for (long i=1;i<=Math.min(100000,n);i++){
            long left = i;
            long right = n-i;
            long sum = left * (left + 1);
            sum /= 2;
            if (sum - right ==k){
                ans = right;
            }
        }
        w.println(ans);

        w.close();
    }
    void debug(Object...args) {
        System.out.println(Arrays.deepToString(args));
    }
    static class pair implements Comparable<pair>{

        int a;
        int b;

        pair(int a,int b){
            this.a = a;
            this.b = b;
        }
        public int compareTo(pair o){
            if(this.b != o.b)return this.b - o.b;
            return this.a - o.a;
        }

    }
    long modinv(long a,long b) {
        long p=power(b,mod-2,mod);

        p=a%mod*p%mod;
        p%=mod;

        return p;

    }
    long power(long x,long y,long mod){
        if(y==0)return 1%mod;
        if(y==1)return x%mod;
        long res=1;
        x=x%mod;
        while(y>0)
        {
            if((y%2)!=0){
                res=(res*x)%mod;
            }
            y=y/2;
            x=(x*x)%mod;
        }
        return res;
    }
    long gcd(long a,long b){

        if(b==0)return a;
        return gcd(b,a%b);
    }
    void sev(int a[],int n){

        for(int i=2;i<=n;i++)a[i]=i;
        for(int i=2;i<=n;i++){

            if(a[i]!=0){
                for(int j=2*i;j<=n;){

                    a[j]=0;
                    j=j+i;
                }
            }

        }

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

        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 String nextLine()
        {
            BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
            String stock = "";
            try
            {
                stock = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return stock;
        }
        public int nextInt()
        {
            int c = read();

            while(isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-')
            {
                sgn = -1;
                c = read();
            }

            int 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 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 double nextDouble()
        {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-')
            {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.')
            {
                if (c == 'e' || c == 'E')
                    return res * Math.pow(10, nextInt());
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.')
            {
                c = read();
                double m = 1;
                while (!isSpaceChar(c))
                {
                    if (c == 'e' || c == 'E')
                        return res * Math.pow(10, nextInt());
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }

        public String readString()
        {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do
            {
                res.appendCodePoint(c);
                c = read();
            }
            while (!isSpaceChar(c));

            return res.toString();
        }

        public boolean isSpaceChar(int c)
        {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next()
        {
            return readString();
        }

        public interface SpaceCharFilter
        {
            public boolean isSpaceChar(int ch);
        }
    }
}


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

public class Cf2 {

    static boolean ok(long n, long k, long eatten) {
        long moves = n-eatten;
        long ans = moves*(moves+1)/2;
        ans -= eatten;
        return ans <= k;
    }

    public static void main(String[] args) {
        FastReader in = new FastReader();
        long n = in.nextInt();
        long k = in.nextInt();
        long left = 0, right = n;
        while (left <= right) {
            long middle = (left+right)/2;
            if (ok(n, k, middle)) right = middle-1;
            else left=middle+1;
        }
        System.out.println(left);
    }

    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


import java.util.Scanner;

public class SportMafia {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int k = sc.nextInt();

		int next = 1;
		int current = 0;
		int result = 0;

		for(int i = 0; i < n; i++) {
			if(current < k) {
				current += next++;
			} else {
				current--;
				result++;
			}
		}

		System.out.println(result);

		sc.close();
	}
}


import java.util.*;
public class algo_1802
{
    public static void main(String args[])
    {
        Scanner ex=new Scanner(System.in);
        int n=ex.nextInt();
        int k=ex.nextInt();
        int x=(int)((Math.sqrt(9.0+8.0*((double)n+(double)k))-3.0)/2.0);
        System.out.println(n-x);
    }
}


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

public class Main
{
	public static void main(String[] args)
	{
		FastReader reader = new FastReader();
		PrintWriter writer = new PrintWriter(System.out);

		long n = reader.nextLong();
		long k = reader.nextLong();

		long s=0;
		long e=n;

		long ans = -1;
		while (s<=e) {
			long m = (s+e)/2;
			long temp = ((n-m)*(n-m+1))/2 - m;

			if (temp < k)
				e = m-1;
			else if (temp > k)
				s = m+1;
			else {
				ans = m;
				break;
			}
		}

		writer.println(ans);
		writer.close();
	}

	static class FastReader
	{
		BufferedReader br;
		StringTokenizer st;

		public FastReader()
		{
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next()
		{
			while (st == null || !st.hasMoreElements())
			{
				try
				{
					st = new StringTokenizer(br.readLine());
				}
				catch (IOException e)
				{
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt()
		{
			return Integer.parseInt(next());
		}

		long nextLong()
		{
			return Long.parseLong(next());
		}

		double nextDouble()
		{
			return Double.parseDouble(next());
		}

		String nextLine()
		{
			String str = "";
			try
			{
				str = br.readLine();
			}
			catch (IOException e)
			{
				e.printStackTrace();
			}
			return str;
		}
	}
}


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

public class B {

    public void solve() throws IOException {
        long n = nextInt(), k = nextInt();
        long c = 2 * (n + k);
        long l = -1, r = 200000;
        while (r - l > 1) {
            long m = l + (r - l) / 2;
            if (m * m + 3 * m >= c) {
                r = m;
            } else {
                l = m;
            }
        }
        out.print(n - r);
    }

    public void run() {
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);

            solve();

            out.close();
        } catch (IOException e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    BufferedReader br;
    StringTokenizer in;
    PrintWriter out;

    public String nextToken() throws IOException {
        while (in == null || !in.hasMoreTokens()) {
            in = new StringTokenizer(br.readLine());
        }
        return in.nextToken();
    }

    public int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    public double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    public long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    public int[] nextArr(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = nextInt();
        }
        return res;
    }

    public static void main(String[] args) throws IOException {
        Locale.setDefault(Locale.US);
        new B().run();
    }
}


// Created by Whiplash99
import java.io.*;
import java.util.*;
public class A
{
    public static void main(String[] args) throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

        long N,K,tmp,ans=0;

        String s[]=br.readLine().trim().split(" ");
        N=Long.parseLong(s[0]);
        K=Long.parseLong(s[1]);

        long l=1,r=N,mid;

        while(l<=r)
        {
            mid=(l+r)/2;

            tmp=mid*(mid+1)/2;
            tmp-=N;
            tmp+=mid;

            if(tmp==K)
            {
                ans=N-mid;
                break;
            }
            else if(tmp>K)
                r=mid-1;
            else
                l=mid+1;
        }
        System.out.println(ans);
    }
}


import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        long n = in.nextLong();
        long k = in.nextLong();
        long disc = (long)(Math.sqrt(9 - 4 * (-2 * n - 2 * k)));
        long x = (-3 + disc) / 2;
        System.out.println(n - x);
    }
}


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

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer tokenizer = new StringTokenizer(reader.readLine());
        int n = Integer.parseInt(tokenizer.nextToken());
        int k = Integer.parseInt(tokenizer.nextToken());
        System.out.println((int)(n-(-3.0+Math.sqrt(9.0+8.0*(n+k)))/2.0));
    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

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

    static class BSportMafia {
        private InputReader in;
        private OutputWriter out;

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            this.in = in;
            this.out = out;
            long n = in.nextInt();
            long k = in.nextInt();
            for (long i = 1; i * (i + 1) / 2 + i <= n + k; i++) {
                if (i * (i + 1) / 2 + i == n + k) {
                    out.println(n - i);
                    return;
                }
            }
        }

    }

    static class InputReader extends InputStream {
        private InputStream stream;
        private byte[] buf = new byte[1 << 16];
        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 nextInt() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        private static boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

    }

    static class OutputWriter {
        private final PrintWriter out;

        public OutputWriter(OutputStream outputStream) {
            out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.out = new PrintWriter(writer);
        }

        public void close() {
            out.close();
        }

        public void println(long i) {
            out.println(i);
        }

    }
}


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

public class Codeforces {

    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

    public static void main(String[] args) {
        FastReader input = new FastReader();
        long n = input.nextLong();
        long K = input.nextLong();
        long root = (long) Math.sqrt(8 * (K+n) + 9);
        if (root * root != 8 * (K+n) + 9){
            root++;
            if (root * root != 8 * (K+n) + 9) root -= 2;
        }
        System.out.println(n - (root - 3) / 2);

    }
}


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

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Comparator.*;

public class Main {
    FastScanner in;
    PrintWriter out;

    private void solve() throws IOException {
        solveB();
    }

    private void solveA() throws IOException {
        int n = in.nextInt(), k = in.nextInt();
        int[] cnt = new int[k];
        for (int i = 0; i < n; i++)
            cnt[in.nextInt() - 1] ^= 1;
        int ans = 0;
        for (int i = 0; i < k; i++)
            ans += cnt[i];
        out.println(n - ans + (ans + 1) / 2);
    }

    private void solveB() throws IOException {
        long n = in.nextLong();
        long c = (n + in.nextLong()) * 2;
        long l = 0, r = (long) 1e9;
        while (l + 1 < r) {
            long m = (l + r) / 2;
            if (m * m + 3 * m >= c)
                r = m;
            else
                l = m;
        }
        out.println(n-r);
    }

    private void solveC() throws IOException {
    }

    private void solveD() throws IOException {
    }

    private void solveE() throws IOException {
    }

    class FastScanner {
        StringTokenizer st;
        BufferedReader br;

        FastScanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        boolean hasNext() throws IOException {
            return br.ready() || (st != null && st.hasMoreTokens());
        }

        int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }

        String nextLine() throws IOException {
            return br.readLine();
        }

        boolean hasNextLine() throws IOException {
            return br.ready();
        }
    }

    private void run() throws IOException {
        in = new FastScanner(System.in); // new FastScanner(new FileInputStream(".in"));
        out = new PrintWriter(System.out); // new PrintWriter(new FileOutputStream(".out"));

        for (int t = 1; t-- > 0; )
            solve();

        out.flush();
        out.close();
    }

    public static void main(String[] args) throws IOException {
        new Main().run();
    }
}


import java.io.*;
import java.math.*;
import java.text.*;
import java.util.*;
import java.util.regex.*;

public class Main {

    public static void main(String[] args) throws IOException {

        InputStreamReader r = new InputStreamReader(System.in);
        BufferedReader f = new BufferedReader(r);

        Scanner sc = new Scanner(System.in);
        long n=sc.nextLong();
        long m=sc.nextLong();
        long sum=0;
        if(n==1){

        }else {
            for (long i = 1; i <= n; i++) {
                sum += i;
                if (sum - (n - i) == m) {
                    sum = n - i;
                    break;
                }
            }
        }
        System.out.println(sum);

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

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

    static class TaskBR574D2 {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            long n = in.nextLong();
            long k = in.nextLong();
            long r = (long) (Math.sqrt(9 + 8 * (n + k)) - 3) / 2;
            out.println(n - r);
        }

    }
}


import java.io.BufferedWriter;
	import java.io.IOException;
	import java.io.InputStream;
	import java.io.OutputStream;
	import java.io.OutputStreamWriter;
	import java.io.PrintWriter;
	import java.io.Writer;
	import java.util.Arrays;
	import java.util.InputMismatchException;
	import java.util.*;
	import java.io.*;
	import java.math.*;
	public class Main7{

	static class Pair
		{
			int x;
			int y;
			public Pair(int x,int y)
			{
				this.x= x;
				this.y= y;
			}

			@Override
					public int hashCode()
					{
						final int temp = 14;
						int ans = 1;
						ans =x*31+y*13;
						return ans;
					}

					// Equal objects must produce the same
					// hash code as long as they are equal
				@Override
				public boolean equals(Object o)
				{
					if (this == o) {
						return true;
					}
					if (o == null) {
						return false;
					}
					if (this.getClass() != o.getClass()) {
						return false;
					}
					Pair other = (Pair)o;
					if (this.x != other.x || this.y!=other.y) {
						return false;
					}
					return true;
				}

		}
		static class Pair1
		{
			String x;
			int y;
			int z;

		}
		static class Compare
		{
			/*static void compare(Pair arr[], int n)
			{
				// Comparator to sort the pair according to second element
				Arrays.sort(arr, new Comparator<Pair>() {
					@Override public int compare(Pair p1, Pair p2)
					{
						if(p1.start>p2.start)
						{
							return 1;
						}
						else if(p1.start==p2.start)
						{
							return 0;
						}
						else
						{
							return -1;
						}
					}
				});
			}
			*/
		}

		public static long pow(long a, long b)
		{
			long result=1;
			while(b>0)
			{
				if (b % 2 != 0)
				{
					result=(result*a)%mod;
					b--;
				}
				a=(a*a)%mod;
				b /= 2;
			}
			return result;
		}
		public static long fact(long num)
		{
					long value=1;
					int i=0;
					for(i=2;i<num;i++)
					{
						value=((value%mod)*i%mod)%mod;
					}
					return value;
				}
				public static int gcd(int a, int b)
				{
					if (a == 0)
						return b;
					return gcd(b%a, a);
				}

		/*		public static long lcm(long a,long b)
				{
					return a * (b / gcd(a, b));
				}
			*/	public static long sum(int h)
				{
					return (h*(h+1)/2);
				}
				/*public static void dfs(int parent,boolean[] visited)
				{
					TreeSet<Integer> arr=new TreeSet<Integer>();
					arr=graph.get(parent);
					visited[parent]=true;
					if(a[parent]==1)
					{
						flag=1;
					}
					if(a[parent]==2)
					{
						flag1=1;
					}
					if(flag==1 && flag1==1)
					{
						return;
					}
					Iterator itr=arr.iterator();
					while(itr.hasNext())
					{
						int num=(int)itr.next();
						if(visited[num]==false)
						{
							dfs(num,visited);
						}
					}
					x1x`
				}*/
			//	static int flag1=0;
				static int[] dis;
				static int mod=1000000007;
				static ArrayList<ArrayList<Integer>> graph;

				public static void bfs(int num,int size)
				{
					boolean[] visited=new boolean[size+1];
					Queue<Integer> q=new LinkedList<>();
					q.add(num);
					ans[num]=1;
					visited[num]=true;
					while(!q.isEmpty())
					{
						int x=q.poll();
						ArrayList<Integer> al=graph.get(x);
						for(int i=0;i<al.size();i++)
						{
							int y=al.get(i);
							if(visited[y]==false)
							{
								q.add(y);
								ans[y]=ans[x]+1;
								visited[y]=true;
							}
						}
					}
				}
				static int[] ans;

			//	static int[] a;

				public static int[] sort(int[] a)
				{
					int n=a.length;
					ArrayList<Integer> ar=new ArrayList<>();
					for(int i=0;i<a.length;i++)
					{
						ar.add(a[i]);
					}
					Collections.sort(ar);
					for(int i=0;i<n;i++)
					{
						a[i]=ar.get(i);
					}
					return a;
				}
			//	static int flag=1;

				static public void main(String args[])throws IOException
				{
		//		    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
				/*	boolean[] prime=new boolean[1000001];
					for(int i=2;i*i<=1000000;i++)
					{
						if(prime[i]==false)
						{
							for(int j=2*i;j<=1000000;j+=i)
							{
								prime[j]=true;
							}
						}
					}
					*/
					int n=i();
					int k=i();
					long low=0;
					long high=k;
					long fin=0;
					long ans=0;
					for(int i=1;i<=n;i++)
					{
						ans+=i;
						if(Math.abs(ans-k)+i==n && ans>=k)
						{
							fin=Math.abs(ans-k);
							break;
						}
					}
					pln(fin+"");
				}

				/**/
				static InputReader in=new InputReader(System.in);
					static OutputWriter out=new OutputWriter(System.out);
					public static long l()
					{
						String s=in.String();
						return Long.parseLong(s);
					}
					public static void pln(String value)
					{
						System.out.println(value);
					}
					public static int i()
					{
						return in.Int();
					}
					public static String s()
					{
						return in.String();
					}
		}

			class InputReader {

				private InputStream stream;
				private byte[] buf = new byte[1024];
				private int curChar;
				private int numChars;
				private SpaceCharFilter filter;

				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 Int() {
					int c = read();
					while (isSpaceChar(c))
						c = read();
					int sgn = 1;
					if (c == '-') {
						sgn = -1;
						c = read();
					}
					int 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 String() {
					int c = read();
					while (isSpaceChar(c))
						c = read();
					StringBuilder res = new StringBuilder();
					do {
						res.appendCodePoint(c);
						c = read();
					} while (!isSpaceChar(c));
					return res.toString();
				}

				public boolean isSpaceChar(int c) {
					if (filter != null)
						return filter.isSpaceChar(c);
					return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
				}

				public String next() {
					return String();
				}

				public interface SpaceCharFilter {
					public boolean isSpaceChar(int ch);
				}
			}

			class OutputWriter {
				private final PrintWriter writer;

				public OutputWriter(OutputStream outputStream) {
					writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
				}

				public OutputWriter(Writer writer) {
					this.writer = new PrintWriter(writer);
				}

				public void print(Object...objects) {
					for (int i = 0; i < objects.length; i++) {
						if (i != 0)
							writer.print(' ');
						writer.print(objects[i]);
					}
				}

				public void printLine(Object...objects) {
					print(objects);
					writer.println();
				}

				public void close() {
					writer.close();
				}

				public void flush() {
					writer.flush();
				}

				}

				class IOUtils {

				public static int[] readIntArray(InputReader in, int size) {
					int[] array = new int[size];
					for (int i = 0; i < size; i++)
						array[i] = in.Int();
					return array;
				}

				}


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

public class B_574 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] input = br.readLine().split(" ");
        int N = Integer.valueOf(input[0]);
        int K = Integer.valueOf(input[1]);
        long sum = 0;
        for(int i = 0; i < N; i++){
            if(sum - (N - i) == K){
                System.out.println(Integer.valueOf(N-i));
                return;
            }
            sum += (i+1);
        }
        System.out.println("0");
    }
}


import java.util.*;
import java.io.*;
public class template {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));
		int n = sc.nextInt();
		int k = sc.nextInt();
		long left = 0;
		long right = n;
		long mid = left+right/2;
		while(left<=right) {
			mid = (left+(right))/2;
			if(((mid+1)*mid)/2-(n-mid)==k) {
				pw.println(n-mid);
				pw.close();
				break;
			}
			else if(((mid+1)*mid)/2-(n-mid)>k) {
				right = mid-1;
			}
			else left = mid+1;
		}
	}
}
@SuppressWarnings("all")
class FastScanner {
    BufferedReader br;
    StringTokenizer st;

    public FastScanner(String s) {
        try {
            br = new BufferedReader(new FileReader(s));
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    public FastScanner() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String nextToken() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(nextToken());
    }

    long nextLong() {
        return Long.parseLong(nextToken());
    }

    double nextDouble() {
        return Double.parseDouble(nextToken());
    }
}


import java.math.*;
import java.util.*;
import java.io.*;
public class Main{
    static StreamTokenizer in=new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
    static BufferedReader buffer=new BufferedReader(new InputStreamReader(System.in));
    static Scanner sc=new Scanner(System.in);
    static PrintWriter out=new PrintWriter(System.out);
    //static InputReader sc=new InputReader(System.in);
    static final int inf=10000000;
    public static void main(String args[])throws Exception {
        double n,k;
        n=sc.nextDouble();
        k=sc.nextDouble();
        double ans=0;
        ans=Math.sqrt(2.25+2*(n+k))-1.5;
        System.out.printf("%.0f\n",n-ans);
    }
    static void ssort(int arr[]){
        int len=arr.length;
        for(int i=0;i<len;i++){
            int t=(int)(len*Math.random());
            int temp=arr[t];
            arr[t]=arr[i];
            arr[i]=temp;
        }
        Arrays.sort(arr);
    }
    static int getInt()throws Exception{
        in.nextToken();
        return  (int)in.nval;
    }
}

class InputReader {
    private final InputStream stream;
    private final byte[] buf = new byte[8192];
    private int curChar, snumChars;
    public InputReader(InputStream st) {
        this.stream = st;
    }
    public int read() {
        if (snumChars == -1)
            throw new InputMismatchException();
        if (curChar >= snumChars) {
            curChar = 0;
            try {
                snumChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (snumChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }

    public int nextInt() {
        int c = read();
        while (isSpaceChar(c)) {
            c = read();
        }
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        int res = 0;
        do {
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

    public long nextLong() {
        int c = read();
        while (isSpaceChar(c)) {
            c = read();
        }
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        long res = 0;
        do {
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

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

    public String readString() {
        int c = read();
        while (isSpaceChar(c)) {
            c = read();
        }
        StringBuilder res = new StringBuilder();
        do {
            res.appendCodePoint(c);
            c = read();
        } while (!isSpaceChar(c));
        return res.toString();
    }

    public String nextLine() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        StringBuilder res = new StringBuilder();
        do {
            res.appendCodePoint(c);
            c = read();
        } while (!isEndOfLine(c));
        return res.toString();
    }

    public boolean isSpaceChar(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    private boolean isEndOfLine(int c) {
        return c == '\n' || c == '\r' || c == -1;
    }

}
/*

 */


import java.io.*;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;

public class B {
    static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
    static MyScanner sc;

    static {
        try {
            sc = new MyScanner();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        doTask();
        out.flush();
    }

    public static void doTask(){
        long n = sc.nextInt();
        long k = sc.nextInt();
        long c = -2*(n+k);
        long d =  9 - 4*c;
        double result = n - (-3 + Math.sqrt(1.0*d))/2;
        out.println(Math.round(result));
    }

    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() throws FileNotFoundException {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine(){
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

    }
}


import java.util.*;

public class B
{
	static long sumN(long n)
	{
		return n * (n + 1) / 2;
	}

	static int binSearchPuts(int n, int k)
	{
		int L = 1;
		int U = n;
		int M = (L + U) / 2;

		while(L <= U)
		{
			long left = sumN(M) - (n - M);

			if(left < k)
			{
				L = M + 1;
			}
			else if(left > k)
			{
				U = M;
			}
			else
			{
				break;
			}

			M = (L + U) / 2;
		}

		return M;
	}

	public static void main(String[] args)
	{
		Scanner input = new Scanner(System.in);

		int n = input.nextInt();
		int k = input.nextInt();

		long ate = n - binSearchPuts(n, k);
		System.out.println(ate);
	}
}


import java.io.*;
import java.math.*;
import java.util.*;
import java.util.stream.*;
import java.lang.management.*;
import static java.lang.Math.abs;
import static java.lang.Math.min;
import static java.lang.Math.max;
import static java.lang.Math.sqrt;
import static java.lang.Integer.signum;

@SuppressWarnings("unchecked")
public class P1177B {

  public void run() throws Exception {
    for (long k = nextLong() - 1, d = 1, dc = 9, sv = 1; true; k -= dc, d++, sv *= 10, dc = sv * d * 9) {
      if (k <= dc) {
        println(Long.toString(sv + k / d).charAt((int)(k % d)));
        break;
      }
    }
  }

  public static void main(String... args) throws Exception {
    br = new BufferedReader(new InputStreamReader(System.in));
    pw = new PrintWriter(new BufferedOutputStream(System.out));
    new P1177B().run();
    br.close();
    pw.close();
    System.err.println("\n[Time : " + (System.currentTimeMillis() - startTime) + " ms]");
    long gct = 0, gcc = 0;
    for (GarbageCollectorMXBean garbageCollectorMXBean : ManagementFactory.getGarbageCollectorMXBeans()) {
      gct += garbageCollectorMXBean.getCollectionTime();
      gcc += garbageCollectorMXBean.getCollectionCount();
    }
    System.err.println("[GC time : " + gct + " ms, count = " + gcc + "]");
  }

  static long startTime = System.currentTimeMillis();
  static BufferedReader br;
  static PrintWriter pw;
  StringTokenizer stok;

  String nextToken() throws IOException {
    while (stok == null || !stok.hasMoreTokens()) {
      String s = br.readLine();
      if (s == null) { return null; }
      stok = new StringTokenizer(s);
    }
    return stok.nextToken();
  }

  void print(byte b) { print("" + b); }
  void print(int i) { print("" + i); }
  void print(long l) { print("" + l); }
  void print(double d) { print("" + d); }
  void print(char c) { print("" + c); }
  void print(Object o) {
    if (o instanceof int[]) { print(Arrays.toString((int [])o));
    } else if (o instanceof long[]) { print(Arrays.toString((long [])o));
    } else if (o instanceof char[]) { print(Arrays.toString((char [])o));
    } else if (o instanceof byte[]) { print(Arrays.toString((byte [])o));
    } else if (o instanceof short[]) { print(Arrays.toString((short [])o));
    } else if (o instanceof boolean[]) { print(Arrays.toString((boolean [])o));
    } else if (o instanceof float[]) { print(Arrays.toString((float [])o));
    } else if (o instanceof double[]) { print(Arrays.toString((double [])o));
    } else if (o instanceof Object[]) { print(Arrays.toString((Object [])o));
    } else { print("" + o); }
  }
  void printsp(int [] a) { for (int i = 0, n = a.length; i < n; print(a[i] + " "), i++); }
  void print(String s) { pw.print(s); }
  void println() { println(""); }
  void println(byte b) { println("" + b); }
  void println(int i) { println("" + i); }
  void println(long l) { println("" + l); }
  void println(double d) { println("" + d); }
  void println(char c) { println("" + c); }
  void println(Object o) { print(o); println(); }
  void println(String s) { pw.println(s); }
  int nextInt() throws IOException { return Integer.parseInt(nextToken()); }
  long nextLong() throws IOException { return Long.parseLong(nextToken()); }
  double nextDouble() throws IOException { return Double.parseDouble(nextToken()); }
  char nextChar() throws IOException { return (char) (br.read()); }
  String next() throws IOException { return nextToken(); }
  String nextLine() throws IOException { return br.readLine(); }
  int [] readInt(int size) throws IOException {
    int [] array = new int [size];
    for (int i = 0; i < size; i++) { array[i] = nextInt(); }
    return array;
  }
  long [] readLong(int size) throws IOException {
    long [] array = new long [size];
    for (int i = 0; i < size; i++) { array[i] = nextLong(); }
    return array;
  }
  double [] readDouble(int size) throws IOException {
    double [] array = new double [size];
    for (int i = 0; i < size; i++) { array[i] = nextDouble(); }
    return array;
  }
  String [] readLines(int size) throws IOException {
    String [] array = new String [size];
    for (int i = 0; i < size; i++) { array[i] = nextLine(); }
    return array;
  }

  int gcd(int a, int b) {
    if (a == 0) return Math.abs(b); if (b == 0) return Math.abs(a);
    a = Math.abs(a); b = Math.abs(b);
    int az = Integer.numberOfTrailingZeros(a), bz = Integer.numberOfTrailingZeros(b);
    a >>>= az; b >>>= bz;
    while (a != b) {
      if (a > b) { a -= b; a >>>= Integer.numberOfTrailingZeros(a); }
            else { b -= a; b >>>= Integer.numberOfTrailingZeros(b); }
    }
    return (a << Math.min(az, bz));
  }

  long gcd(long a, long b) {
    if (a == 0) return Math.abs(b); if (b == 0) return Math.abs(a);
    a = Math.abs(a); b = Math.abs(b);
    int az = Long.numberOfTrailingZeros(a), bz = Long.numberOfTrailingZeros(b);
    a >>>= az; b >>>= bz;
    while (a != b) {
      if (a > b) { a -= b; a >>>= Long.numberOfTrailingZeros(a); }
            else { b -= a; b >>>= Long.numberOfTrailingZeros(b); }
    }
    return (a << Math.min(az, bz));
  }

  void shuffle(int [] a) { // RANDOM shuffle
    Random r = new Random();
    for (int i = a.length - 1, j, t; i >= 0; j = r.nextInt(a.length), t = a[i], a[i] = a[j], a[j] = t, i--);
  }

  void shuffle(int [] a, int m) { // QUICK shuffle
    for (int i = 0, n = a.length, j = m % n, t; i < n; t = a[i], a[i] = a[j], a[j] = t, i++, j = (i * m) % n);
  }

  void shuffle(long [] a) {
    Random r = new Random();
    for (int i = a.length - 1; i >= 0; i--) {
      int j = r.nextInt(a.length);
      long t = a[i]; a[i] = a[j]; a[j] = t;
    }
  }

  void shuffle(Object [] a) {
    Random r = new Random();
    for (int i = a.length - 1; i >= 0; i--) {
      int j = r.nextInt(a.length);
      Object t = a[i]; a[i] = a[j]; a[j] = t;
    }
  }

  int [] sort(int [] a) {
    final int SHIFT = 16, MASK = (1 << SHIFT) - 1, SIZE = (1 << SHIFT) + 1;
    int n = a.length, ta [] = new int [n], ai [] = new int [SIZE];
    for (int i = 0; i < n; ai[(a[i] & MASK) + 1]++, i++);
    for (int i = 1; i < SIZE; ai[i] += ai[i - 1], i++);
    for (int i = 0; i < n; ta[ai[a[i] & MASK]++] = a[i], i++);
    int [] t = a; a = ta; ta = t;
    ai = new int [SIZE];
    for (int i = 0; i < n; ai[(a[i] >> SHIFT) + 1]++, i++);
    for (int i = 1; i < SIZE; ai[i] += ai[i - 1], i++);
    for (int i = 0; i < n; ta[ai[a[i] >> SHIFT]++] = a[i], i++);
    return ta;
  }

  void flush() {
    pw.flush();
  }

  void pause() {
    flush(); System.console().readLine();
  }
}


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

public class Main {
    public static void main(String[] args) throws IOException {
        FastScanner in = new FastScanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        new Main().run(in, out);
        out.close();
    }

    public static long mod = 17352642619633L;

    void run(FastScanner in, PrintWriter out) {
        // kth digit
        long K = in.nextLong();

        // which number encompasses the Kth digit

        long lo = 1;
        long hi = (long)1e12+1;

        while (lo < hi) {
            long m = (lo+hi)>>1;
            long d = numDigitsLte(m);
            if (d <= K) {
                lo = m+1;
            } else {
                hi = m;
            }
        }

        // 123[1]1391 = m digits
        long numDigits = numDigitsLte(lo);
        if (numDigitsLte(lo-1) == K) {
            out.println((((lo-1)%10)+10)%10);
        } else {
            int offset = (int)(numDigits-K);

            // out.print(lo + " ");
            List<Long> digits = new ArrayList<>();
            while (lo > 0) {
                digits.add(lo%10);
                lo /= 10;
            }
            // backwards
            // before : 1[2]3456
            // in list: 6543[2]1
            // offset = 4
            out.println(digits.get(offset));

        }
    }

    static long[] dig = new long[15];
    static {
        for (int i = 1; i < dig.length; i++) {
            dig[i] = 9 * (long)Math.pow(10, i-1) * i;
        }

        for (int i = 1; i < dig.length; i++) {
            dig[i] += dig[i-1];
        }
    }

    long numDigitsLte(long m) {
        if (m <= 9) return m;

        int numDigits = 0;
        long M = m;
        while (M > 0) {
            numDigits++;
            M /= 10;
        }

        long ret = dig[numDigits-1];
        ret += (m-(long)Math.pow(10, numDigits-1)+1)*numDigits;
        return ret;

        // digits below
        // 9 + 90 + 900
        // [1-9], [10-99], [100-999]
        // 9, 90*2, 900*3, ...
        // 9999..

        // 9138
        // [1-1000), [1000,9138]
    }

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(InputStream in) {
            br = new BufferedReader(new InputStreamReader(in));
            st = null;
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}


import java.util.*;
public class global{
	public static void main(String s[]){
		Scanner sc = new Scanner(System.in);
			long n = sc.nextLong();
			String st = String.valueOf(n);
			if(st.length()==1){
				System.out.println(n);
			}else{
				long val = 1;
				long prev=9;
				long total=9;
				long late=9;
				for(int i=2;i<=12;i++){
					val*=10;

					total+=i*(val*9);
					if(n<=total){
						long diff = n-late;
						long div = diff/i;
						long mod = diff%i;

						if(mod==0){
							prev+=div;
							System.out.println((prev)%10);
							break;
						}else{
							prev+=div+1;
							String fg = String.valueOf(prev);
							System.out.println(fg.charAt((int)mod-1));
							break;
						}
					}
					prev+=(9*val);
					late=total;
				}

			}

		}
	}


import java.io.FileNotFoundException;
import java.util.Scanner;

public class P1177A {

    public static void main(String[] args) throws FileNotFoundException {

        Scanner in = new Scanner(System.in);
        // Scanner in = new Scanner(new File("input.txt"));
        System.out.println(solve(in.nextLong()));

    }

    private static String solve(long k) {

        long digitCnt = 1;
        long nine = 9;

        while (k > nine * digitCnt) {
            k -= nine * digitCnt;
            nine *= 10;
            digitCnt++;
        }

        long num = nine / 9 - 1 + (k - 1) / digitCnt + 1;
        return String.valueOf(String.valueOf(num).charAt((int) ((k - 1) % digitCnt)));

    }

}


import java.util.Scanner;
public class Solution {
    public static void main(String[] args) {
        long b=0;long p=1;
        Scanner s=new Scanner(System.in);
        long m=s.nextLong();
        long x=1;
        do{
            p=(m+b)/x;
            b=10*b+10;
            x++;
        }while(p/(long)Math.pow(10, x-1)!=0);
        rest :
        x--;b=b/10-1;
        b=x*p-b;
        b=m-b;
        b=x-b-1;
        p/=(long)Math.pow(10, b);
        p%=10;
        System.out.println(p);
    }
}


import java.util.Scanner;
public class Main
{
	public static void main(String[] args) {
	    Scanner sc =new Scanner(System.in);
	    long n=sc.nextLong();
	    long x=1;
	    long ar=0;
	    tag:for(long i=1;;i++)
	    {
	        ar+=9*i*x;
	        if(ar>=n)
	        {
	            long d = n - (ar-9*i*x);
	            long ans = x+d/i;
	            long p=d%i;
	            if(p==0)
	            {
	                p=i;
	                ans--;
	            }
	            p=i-p;
	            p++;
	            long fns=0;
	            //System.out.println(ans);
	            while(p!=0)
	            {
	                fns=ans%10;
	                ans/=10;
	                p--;
	            }
	            System.out.println(fns);

	            break tag;
	        }
	        x*=10;
	    }
	}
}


// Change Of Plans BABY.... Change Of Plans //
import java.io.*;
import java.util.*;
import java.util.Queue;
import static java.lang.Math.*;

public class digitSequence {

    static void MainSolution() {
        long k = nl() - 1;

        for (int i = 1; ; i++) {
            long temp=9L*i*fastPow(10,i-1);
            if(k<temp){
                long x=k/i;
                long y=k%i;
                long ans=(x+fastPow(10,i-1))/fastPow(10,i-y-1);
                pl(ans%10);
                break;
            }
            k-=temp;
        }
    }

    static long fastPow(long b, long e) {
        if (e == 0) return 1;
        if ((e & 1) == 1) return b * fastPow(b, e >> 1) * fastPow(b, e >> 1);
        return fastPow(b, e >> 1) * fastPow(b, e >> 1);
    }

    /*----------------------------------------------------------------------------------------------------------------*/
    //THE DON'T CARE ZONE BEGINS HERE...\\
    static int mod9 = 1_000_000_007;
    static int n, m, l, k, t;
    static AwesomeInput input = new AwesomeInput(System.in);
    static PrintWriter pw = new PrintWriter(System.out, true);

    // The Awesome Input Code is a fast IO method //
    static class AwesomeInput {
        private InputStream letsDoIT;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;

        private AwesomeInput(InputStream incoming) {
            this.letsDoIT = incoming;
        }

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

        private long ForLong() {
            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;
        }

        private String ForString() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            }
            while (!isSpaceChar(c));

            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            boolean isSpaceChar(int ch);
        }
    }

    // functions to take input//
    static int ni() {
        return (int) input.ForLong();
    }

    static String ns() {
        return input.ForString();
    }

    static long nl() {
        return input.ForLong();
    }

    static double nd() throws IOException {
        return Double.parseDouble(new BufferedReader(new InputStreamReader(System.in)).readLine());
    }

    //functions to give output
    static void pl() {
        pw.println();
    }

    static void p(Object o) {
        pw.print(o + " ");
    }

    static void pws(Object o) {
        pw.print(o + "");
    }

    static void pl(Object o) {
        pw.println(o);
    }

    // Fast Sort is Radix Sort
    public static int[] fastSort(int[] f) {
        int n = f.length;
        int[] to = new int[n];
        {
            int[] b = new int[65537];
            for (int i = 0; i < n; i++) b[1 + (f[i] & 0xffff)]++;
            for (int i = 1; i <= 65536; i++) b[i] += b[i - 1];
            for (int i = 0; i < n; i++) to[b[f[i] & 0xffff]++] = f[i];
            int[] d = f;
            f = to;
            to = d;
        }
        {
            int[] b = new int[65537];
            for (int i = 0; i < n; i++) b[1 + (f[i] >>> 16)]++;
            for (int i = 1; i <= 65536; i++) b[i] += b[i - 1];
            for (int i = 0; i < n; i++) to[b[f[i] >>> 16]++] = f[i];
            int[] d = f;
            f = to;
            to = d;
        }
        return f;
    }

    public static void main(String[] args) {      //threading has been used to increase the stack size.

        new Thread(null, null, "Vengeance", 1 << 25)  //the last parameter is stack size desired.
        {
            public void run() {
                try {
                    double s = System.currentTimeMillis();
                    MainSolution();
                    //pl(("\nExecution Time : " + ((double) System.currentTimeMillis() - s) / 1000) + " s");
                    pw.flush();
                    pw.close();
                } catch (Exception e) {
                    e.printStackTrace();
                    System.exit(1);
                }
            }
        }.start();
    }
}


/**
 * @(#)DigitSequence.java
 *
 *
 * @author
 * @version 1.00 2019/6/1
 */
import java.io.*;
import java.util.*;
public class DigitSequence {

    /**
     * Creates a new instance of DigitSequence.
     */
    public DigitSequence() {
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        long k=in.nextLong();
        long[] end=new long[12];
        end[0]=-1;
        for (int i=1; i<end.length; i++) {
        	end[i]=(i*(long)(Math.pow(10,i)));
        	end[i]-=(((long)(Math.pow(10,i))-1)/9);
        }
        //System.out.println(Arrays.toString(end));
        int st=0;//st=1 {0,9}; st=2 {10, 189}; st=3 {190-2889}; st=4 {2890-38889}
       	for (int i=1; i<end.length; i++) {
       		if (k>=end[i-1]+1 && k<=end[i]) st=i;
       	}
       	//System.out.println("st " + st);
       	long diff=k-end[st-1];
       	long mod=((diff+st-1)%st);
       	//System.out.println(mod);
       	long digit=-1;

       	int addOn=0;
       	if (mod==0) addOn=1;
       	if (mod==st-1) addOn=-1;
       	digit=(diff/(st*(long)(Math.pow(10,st-1-mod))));
       	digit+=addOn;
       	digit%=10;
       	System.out.println(digit);
       	//98888888889
       	//98888888879
       	//1088888888889
       	//1088888888878
    }
}


import java.util.Scanner;

public class A1177 {
    public static long exponential(long a, long b){
        long result = 1;
        for(int i=0;i<b;i++){
            result *= a;
        }
        return result;
    }
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        long  k = scanner.nextLong();
        //int k =21;
        long sum = 0;
        long i=1;
        while(true){
            long interval = 9 * exponential(10,i-1) * i;
            if(sum + interval >= k){
                break;
            } else {
                i++;
                sum += interval;
            }
        }
        long t = k-sum;
        long targetNumber = exponential(10, i-1) + (t-1)/i;
        String s = "" + targetNumber;
        int hedef = (int)((t-1)%i);
        System.out.println(s.charAt(hedef));
    }
}


import java.util.Scanner;

public class P1177A {

	public static void main(String[] args) {

		try (Scanner sc = new Scanner(System.in)) {

			long k = sc.nextLong();
			int pow = 1;

			while ((long) ((Math.pow(10, pow) - Math.pow(10, pow - 1)) * pow) < k) {
				k -= (long) ((Math.pow(10, pow) - Math.pow(10, pow - 1)) * pow);
				pow++;
			}
			// System.out.println(k + " " + pow);

			k--;
			long n = (long) Math.pow(10, pow - 1) + k / pow;
			k %= pow;
			// System.out.println(k + " " + n);

			System.out.println(String.valueOf(n).charAt((int) k));

		}
		catch (Exception e) {
			e.printStackTrace();
		}
	}
}


import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class Main {
    public static void main(String[] args) throws IOException {
        FastScanner sc=new FastScanner();
        long K = sc.nextLong();
        long nums = 9;
        int digits = 1;
        while (K > nums*digits) {
        	K -= nums*digits;
        	nums *= 10;
        	digits++;
        }
        long removal = (K-1)/digits;
        int pos = (int)((K-1)%digits);
        long base = (long)Math.pow(10,digits-1);
        String num = Long.toString(base+removal);
        System.out.println(num.charAt(pos));
    }

    static class FastScanner
    {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

public class Main {

	static class Task {

		int NN = 1000001;
		int MOD = 1000000007;
		int INF = 2000000000;
		long INFINITY = 2000000000000000000L;

		public void solve(InputReader in, PrintWriter out) {
			long k = in.nextLong();
			for(long mul = 1,d=1;;mul*=10,++d) {
				if(k > 9*mul*d) {
					k -= 9*mul*d;
				} else {
					for(long i=1;i<=9;++i) {
						if(k > mul*d) {
							k -= mul*d;
						} else {
							--k;
							long num = k / d;
							k %= d;
							String str = String.valueOf(num);
							while(str.length() < d - 1) {
								str = "0" + str;
							}
							str = String.valueOf(i) + str;
							out.println(str.charAt((int) k));return;
						}
					}
				}
			}
		}

	}

	static void prepareIO(boolean isFileIO) {
		//long t1 = System.currentTimeMillis();
		Task solver = new Task();
		// Standard IO
		if(!isFileIO) {
			InputStream inputStream = System.in;
	        OutputStream outputStream = System.out;
	        InputReader in = new InputReader(inputStream);
	        PrintWriter out = new PrintWriter(outputStream);
	        solver.solve(in, out);
	        //out.println("time(s): " + (1.0*(System.currentTimeMillis()-t1))/1000.0);
	        out.close();
		}
        // File IO
		else {
			String IPfilePath = System.getProperty("user.home") + "/Downloads/ip.in";
	        String OPfilePath = System.getProperty("user.home") + "/Downloads/op.out";
	        InputReader fin = new InputReader(IPfilePath);
	        PrintWriter fout = null;
	        try {
				fout = new PrintWriter(new File(OPfilePath));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
	        solver.solve(fin, fout);
	        //fout.println("time(s): " + (1.0*(System.currentTimeMillis()-t1))/1000.0);
	        fout.close();
		}
	}

	public static void main(String[] args) {
        prepareIO(false);
	}

	static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public InputReader(String filePath) {
        	File file = new File(filePath);
            try {
				reader = new BufferedReader(new FileReader(file));
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
            tokenizer = null;
        }

        public String nextLine() {
        	String str = "";
        	try {
				str = reader.readLine();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
        	return str;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
        	return Double.parseDouble(next());
        }

    }

}


import java.util.Scanner;

public class Main {
    static class LeftOver {
        int a;
        long b;
        long c;
        LeftOver(int a, long b, long c) {
            this.a = a;
            this.b = b;
            this.c = c;
        }
    }

    private static long pow(long base, long coe) {
        if (coe == 0)
            return 1;
        if (coe == 1)
            return base;
        long res = pow(base, coe / 2);
        if (coe % 2 == 0) {
            return res * res;
        } else {
            return res * res * base;
        }
    }

    private static void getLen(long n) {
        long tmp = 0;
        int cnt = 0;
        while(tmp < n) {
            ++cnt;
            tmp += cnt * 9 * pow(10, cnt - 1);
        }
        if (tmp == n)
            System.out.println("9");
        else {
            tmp -= cnt * 9 * pow(10, cnt - 1);
            long ans = (n - tmp - 1) / cnt + pow(10, cnt - 1);
            System.out.println(String.valueOf(ans).charAt((int) ((n - tmp - 1) % cnt)));
        }
    }

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        long n = sc.nextLong();

        getLen(n);
    }
}


import java.util.Scanner;

public class BDigitSequence {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        long k = scan.nextLong();

        long digits = 1;
        long counter = 9L;

        while(k > counter * digits) {
            k -= counter * digits;
            counter *= 10;
            digits++;
        }

        long num = (long)(Math.ceil((double)k/digits));
        String s = String.valueOf((long)Math.pow(10,digits-1) - 1 + num );

        System.out.println(s.charAt((int)((k+digits-1)%digits)));
    }
}


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

public class digits {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        long k = Long.parseLong(br.readLine());
        long temp = 9 * (int)Math.pow(10,0);
        int count = 0;
        long initial = 0;
        while(k > temp) {
            count++;
            initial = temp;
            temp += 9 * (long)Math.pow(10,count)*(count+1);
        }
        long index = (k-initial-1)%(count+1);
        long num = (long)Math.pow(10,count) + (k-initial-1)/(count+1);
        System.out.println((num+"").charAt((int)index));
    }
}


import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        long k = in.nextLong();
        long t = 1;
        long l = 1;
        if(k <= 9) {
            System.out.print(k);
            System.exit(0);
        }
        long x = 9;
        while(true) {
            ++l;
            t *= 10;
            x += 9 * l * t;
            if(x >= k) {
                break;
            }
        }
        if(x == k) {
            System.out.print(9);
            System.exit(0);
        }
        x -= 9 * l * t;
        long a = (k - x) / l;
        if((k - x) % l == 0) {
            x = t + a - 1;
            System.out.print(x % 10);
        } else {
            k -= (x + a * l);
            x = t + a;
            String s = Long.toString(x);
            System.out.print(s.charAt((int)k - 1));
        }
    }
}


import java.io.*;
import java.math.BigDecimal;
import java.math.MathContext;
import java.util.*;

public class Main {
  static int len(long n) {
    int res = 0;
    while (n > 0) {
      n /= 10;
      res++;
    }
    return res;
  }
  static long big(int len) {
    long p = 1;
    while (len-- > 0) p *= 10;
    return p - 1;
  }
  static long small(int len) {
    return big(len - 1) + 1;
  }
  static long cnt(long n) {
    int len = len(n);
    long cnt = 0;
    for (int l = 1; l < len; l++)
      cnt += 1l * l * (big(l) - small(l) + 1);
    cnt += 1l * len * (n - small(len));
    return cnt;
  }
  public static void main(String[] args) throws Exception {
    Scanner sc = new Scanner(System.in);
    PrintWriter out = new PrintWriter(System.out);

    long k = sc.nextLong();
    if (k == 1) {
      System.out.println(1);
      return;
    }
    long lo = 1, hi = k, res = 1;
    while(lo <= hi) {
      long mid = lo + hi >> 1L;
      if(cnt(mid) < k) {
        res = mid;
        lo = mid + 1;
      } else {
        hi = mid - 1;
      }
    }

    ArrayList<Integer> digits = new ArrayList<>();
    long tmp = res;
    while (tmp > 0) {
      digits.add((int)(tmp % 10));
      tmp /= 10;
    }
//    System.err.println("RES " + res);
//    System.err.println("DIGITS " + digits);
//    System.err.println("Cnt Res " + cnt(res));
    Collections.reverse(digits);
    out.println(digits.get((int)(k - cnt(res) - 1)));
    out.flush();
  }

  static class Scanner {
    StringTokenizer st;
    BufferedReader br;

    public Scanner(InputStream s) {
      br = new BufferedReader(new InputStreamReader(s));
    }

    public Scanner(FileReader f) {
      br = new BufferedReader(f);
    }

    public String next() throws IOException {
      while (st == null || !st.hasMoreTokens())
        st = new StringTokenizer(br.readLine());
      return st.nextToken();
    }

    public int nextInt() throws IOException {
      return Integer.parseInt(next());
    }

    public long nextLong() throws IOException {
      return Long.parseLong(next());
    }

    public String nextLine() throws IOException {
      return br.readLine();
    }

    public double nextDouble() throws IOException {
      String x = next();
      StringBuilder sb = new StringBuilder("0");
      double res = 0, f = 1;
      boolean dec = false, neg = false;
      int start = 0;
      if (x.charAt(0) == '-') {
        neg = true;
        start++;
      }
      for (int i = start; i < x.length(); i++)
        if (x.charAt(i) == '.') {
          res = Long.parseLong(sb.toString());
          sb = new StringBuilder("0");
          dec = true;
        } else {
          sb.append(x.charAt(i));
          if (dec)
            f *= 10;
        }
      res += Long.parseLong(sb.toString()) / f;
      return res * (neg ? -1 : 1);
    }

    public boolean ready() throws IOException {
      return br.ready();
    }

  }
}


import java.util.Scanner;

public class DigitsSequence2 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long index = scanner.nextLong();
        solution1(index);

    }

    static void solution1(Long index){
        int i = 1;  // group number
        long len = 9;    // the max length
        long max = 9;    // the max integer
        while(len < index){
            long tmp = 9 * (long) Math.pow(10, i);
            i++;
            len += i * tmp;
            max += tmp;
        }
        long diff = len - index; // the digit number between index and len
        long laterCount = diff / i;  // the number after index
        int remainder = (int) (diff % i);
        long current = max - laterCount; // the number of the index
        int k = i - 1 - remainder;
        System.out.println(String.valueOf(current).charAt(k));
    }
}


import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;

public class _v14 {

    public static void main(String args[]){

        PrintWriter out = new PrintWriter(System.out);
        Reader in = new Reader();
        long k = in.nextLong();
        if(k<10){
            System.out.println(k);
            return;
        }
        long sum = 0;
        long cur = 9;
        long prev = 0;
        int count = 1;
        while(k>cur){
            k= k - cur;
            sum  = sum + cur/count;
            prev = cur;
            cur = 9*(count+1)*(long)Math.pow(10,count);
            count++;
        }

        long num = k/(count);
        sum = sum + num;

        if(k%count == 0){
            System.out.println(sum%10);
        }
        else{
            sum++;
            k = k%(count);
            String str = String.valueOf(sum);
            System.out.println(str.charAt((int)k-1));
        }

        out.flush();
        out.close();
    }
    static class Reader {

        private InputStream mIs;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public Reader() {
            this(System.in);
        }

        public Reader(InputStream is) {
            mIs = is;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();

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

        public String nextLine() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isEndOfLine(c));
            return res.toString();
        }

        public String next() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        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 int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int 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 boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public boolean isEndOfLine(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }

    }

}