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

public class Main {
    public static void main(String[] args) throws FileNotFoundException {
        ConsoleIO io = new ConsoleIO(new InputStreamReader(System.in), new PrintWriter(System.out));

//        String fileName = "C-large-practice";
//        ConsoleIO io = new ConsoleIO(new FileReader("D:\\Dropbox\\code\\practice\\jb\\src\\" + fileName + ".in"), new PrintWriter(new File("D:\\Dropbox\\code\\practice\\jb\\src\\" + fileName + ".out")));

        new Main(io).solve();
//        new Main(io).solveLocal();

        io.close();
    }

    ConsoleIO io;

    Main(ConsoleIO io) {
        this.io = io;
    }

    ConsoleIO opt;

    Main(ConsoleIO io, ConsoleIO opt) {
        this.io = io;
        this.opt = opt;
    }

    List<List<Integer>> gr = new ArrayList<>();

    long MOD = 1_000_000_007;

    public void solve() {
        StringBuilder sb = new StringBuilder();
        int q = io.ri();
        for(int i = 0; i < q; i++){
            long n = io.readLong();
            long k = io.readLong();
            if(i>0)sb.append(System.lineSeparator());
            boolean done = false;

            if(n==2 && k == 3){
                sb.append("NO");
                done = true;
            }

            for(int p = 0;n>0 && !done;p++, n--){
                long count = (1L << (p*2));
                if(k>count){
                    k-=count;
                }else{

                    long path = p==0?1:(1L<<(p-1))*2+((1L<<(p-1))-1)*2+1;

                    if(k<path){
                        sb.append("YES " + n);
                    }else{
                        sb.append("YES " + (n-1));
                    }
                    done = true;
                }
            }

            if(!done){
                sb.append("NO");
            }

        }
        io.writeLine(sb.toString());
    }

}

class ConsoleIO {

    BufferedReader br;
    PrintWriter out;
    public ConsoleIO(Reader reader, PrintWriter writer){br = new BufferedReader(reader);out = writer;}
    public void flush(){this.out.flush();}
    public void close(){this.out.close();}
    public void writeLine(String s) {this.out.println(s);}
    public void writeInt(int a) {this.out.print(a);this.out.print(' ');}
    public void writeWord(String s){
        this.out.print(s);
    }
    public void writeIntArray(int[] a, int k, String separator) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < k; i++) {
            if (i > 0) sb.append(separator);
            sb.append(a[i]);
        }
        this.writeLine(sb.toString());
    }
    public void writeLongArray(long[] a, int k, String separator) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < k; i++) {
            if (i > 0) sb.append(separator);
            sb.append(a[i]);
        }
        this.writeLine(sb.toString());
    }
    public int read(char[] buf, int len){try {return br.read(buf,0,len);}catch (Exception ex){ return -1; }}
    public String readLine() {try {return br.readLine();}catch (Exception ex){ return "";}}
    public long[] readLongArray() {
        String[]n=this.readLine().trim().split("\\s+");long[]r=new long[n.length];
        for(int i=0;i<n.length;i++)r[i]=Long.parseLong(n[i]);
        return r;
    }
    public int[] readIntArray() {
        String[]n=this.readLine().trim().split("\\s+");int[]r=new int[n.length];
        for(int i=0;i<n.length;i++)r[i]=Integer.parseInt(n[i]);
        return r;
    }
    public int[] readIntArray(int n) {
        int[] res = new int[n];
        char[] all = this.readLine().toCharArray();
        int cur = 0;boolean have = false;
        int k = 0;
        boolean neg = false;
        for(int i = 0;i<all.length;i++){
            if(all[i]>='0' && all[i]<='9'){
                cur = cur*10+all[i]-'0';
                have = true;
            }else if(all[i]=='-') {
                neg = true;
            }
            else if(have){
                res[k++] = neg?-cur:cur;
                cur = 0;
                have = false;
                neg = false;
            }
        }
        if(have)res[k++] = neg?-cur:cur;
        return res;
    }
    public int ri() {
        try {
            int r = 0;
            boolean start = false;
            boolean neg = false;
            while (true) {
                int c = br.read();
                if (c >= '0' && c <= '9') {
                    r = r * 10 + c - '0';
                    start = true;
                } else if (!start && c == '-') {
                    start = true;
                    neg = true;
                } else if (start || c == -1) return neg ? -r : r;
            }
        } catch (Exception ex) {
            return -1;
        }
    }
    public long readLong() {
        try {
            long r = 0;
            boolean start = false;
            boolean neg = false;
            while (true) {
                int c = br.read();
                if (c >= '0' && c <= '9') {
                    r = r * 10 + c - '0';
                    start = true;
                } else if (!start && c == '-') {
                    start = true;
                    neg = true;
                } else if (start || c == -1) return neg ? -r : r;
            }
        } catch (Exception ex) {
            return -1;
        }
    }
    public String readWord() {
        try {
            boolean start = false;
            StringBuilder sb = new StringBuilder();
            while (true) {
                int c = br.read();
                if (c!= ' ' && c!= '\r' && c!='\n' && c!='\t') {
                    sb.append((char)c);
                    start = true;
                } else if (start || c == -1) return sb.toString();
            }
        } catch (Exception ex) {
            return "";
        }
    }
    public char readSymbol() {
        try {
            while (true) {
                int c = br.read();
                if (c != ' ' && c != '\r' && c != '\n' && c != '\t') {
                    return (char) c;
                }
            }
        } catch (Exception ex) {
            return 0;
        }
    }
//public char readChar(){try {return (char)br.read();}catch (Exception ex){ return 0; }}
}
class Pair {
    public Pair(int a, int b) {this.a = a;this.b = b;}
    public int a;
    public int b;
}
class PairLL {
    public PairLL(long a, long b) {this.a = a;this.b = b;}
    public long a;
    public long b;
}
class Triple {
    public Triple(int a, int b, int c) {this.a = a;this.b = b;this.c = c;}
    public int a;
    public int b;
    public int c;
}


/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
What do you think? What do you think?
1st on Billboard, what do you think of it
Next is a Grammy, what do you think of it
However you think, I’m sorry, but shit, I have no fcking interest
*******************************
I'm standing on top of my Monopoly board
That means I'm on top of my game and it don't stop
til my hip don't hop anymore
https://www.a2oj.com/Ladder16.html
*******************************
300iq as writer = Sad!
*/
import java.util.*;
import java.io.*;
import java.math.*;

   public class x1080D
   {
      public static void main(String hi[]) throws Exception
      {
         long[] dp = new long[32];
         for(int i=1; i <= 31; i++)
            dp[i] = 1+4*dp[i-1];
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int T = Integer.parseInt(st.nextToken());
         StringBuilder sb = new StringBuilder();
         matcha:while(T-->0)
         {
            st = new StringTokenizer(infile.readLine());
            int N = Integer.parseInt(st.nextToken());
            long K = Long.parseLong(st.nextToken());
            if(N >= 32 || K == 1)
               sb.append("YES "+(N-1)+"\n");
            else if(dp[N] == K)
               sb.append("YES 0\n");
            else if(dp[N] < K)
               sb.append("NO\n");
            else
            {
               long total = 3L;
               long length = 2;
               for(int res=N-1; res >= 0; res--)
               {
                  long min = 1+3*dp[N-1-res];
                  long max = min+dp[N-1];
                  long cansplit = total-2*length+1;
                  max += dp[res]*cansplit;
                  if(min <= K && K <= max)
                  {
                     sb.append("YES "+res+"\n");
                     continue matcha;
                  }
                  length <<= 1;
                  total *= 4;
               }
               sb.append("NO\n");
            }
         }
         System.out.print(sb);
      }
   }


//package que_a;

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

public class utkarsh {

    InputStream is;
    PrintWriter out;

    long mod = (long)(1e9 + 7), inf = (long)(3e18);

    void solve() {
        //SZ = sieve(); //SZ = 1000001;
        int q = ni();
        while(q-- > 0) {
            long n = nl(), k = nl();
            if(n <= 31) {
                long m = (long)(Math.pow(4, n));
                long x = (m - 1) / 3;
                if(k > x) {
                    out.println("NO");  continue;
                }
                long b = 0, p = 1, d = 1; x = 2;
                while(k > b) {
                    n--;
                    k -= p;
                    m /= 4;     if(m == 0)  break;
                    b += d * (m - 1) / 3;
                    p += x;
                    x <<= 1;
                    d += x;
                }
                out.println((n >= 0 && k >= 0 && k <= b) ? ("YES "+ n) : "NO");
            } else {
                out.println("YES "+ (n-1));
            }
        }
    }

    long mp(long b, long e, long mod) {
        b %= mod;
        long r = 1;
        while(e > 0) {
            if((e & 1) == 1) {
                r *= b; r %= mod;
            }
            b *= b; b %= mod;
            e >>= 1;
        }
        return r;
    }

    //---------- I/O Template ----------

    public static void main(String[] args) { new utkarsh().run(); }
    void run() {
        is = System.in;
        out = new PrintWriter(System.out);
        solve();
        out.flush();
    }

    byte input[] = new byte[1024];
    int len = 0, ptr = 0;

    int readByte() {
        if(ptr >= len) { ptr = 0;
            try { len = is.read(input); }
            catch(IOException e) { throw new InputMismatchException(); }
            if(len <= 0) { return -1; }
        } return input[ptr++];
    }
    boolean isSpaceChar(int c) { return !( c >= 33 && c <= 126 ); }
    int skip() {
        int b = readByte();
        while(b != -1 && isSpaceChar(b)) { b = readByte(); }
        return b;
    }

    char nc() { return (char)skip(); }
    String ns() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while(!isSpaceChar(b)) { sb.appendCodePoint(b); b = readByte(); }
        return sb.toString();
    }
    String nLine() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while( !(isSpaceChar(b) && b != ' ') ) { sb.appendCodePoint(b); b = readByte(); }
        return sb.toString();
    }
    int ni() {
        int n = 0, b = readByte();
        boolean minus = false;
        while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')) { b = readByte(); }
        if(b == '-') { minus = true; b = readByte(); }
        if(b == -1) { return -1; }  //no input
        while(b >= '0' && b <= '9') { n = n * 10 + (b - '0'); b = readByte(); }
        return minus ? -n : n;
    }
    long nl() {
        long n = 0L;    int b = readByte();
        boolean minus = false;
        while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')) { b = readByte(); }
        if(b == '-') { minus = true; b = readByte(); }
        while(b >= '0' && b <= '9') { n = n * 10 + (b - '0'); b = readByte(); }
        return minus ? -n : n;
    }

    double nd() { return Double.parseDouble(ns()); }
    float nf() { return Float.parseFloat(ns()); }
    int[] na(int n) {
        int a[] = new int[n];
        for(int i = 0; i < n; i++) { a[i] = ni(); }
        return a;
    }
    char[] ns(int n) {
        char c[] = new char[n];
        int i, b = skip();
        for(i = 0; i < n; i++) {
            if(isSpaceChar(b)) { break; }
            c[i] = (char)b; b = readByte();
        } return i == n ? c : Arrays.copyOf(c,i);
    }
}


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

public class E implements Runnable {
	public static void main (String[] args) {new Thread(null, new E(), "_cf", 1 << 28).start();}

	long oo = (long)2e18;

	public void run() {
		FastScanner fs = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		System.err.println("Go!");

		int t = fs.nextInt();
		while(t-->0) {
			int n = fs.nextInt();
			long k = fs.nextLong();
			long toCut = 1, numSquares = 1, free = 0;
			int cuts = 0;
			while(true) {
				if(cuts >= n) {
					k = oo;
					break;
				}
				k -= toCut;
				if(k < 0) {
					k = oo;
					break;
				}
				cuts++;
				try {
					free = Math.addExact(free, Math.multiplyExact(numSquares, getVal(n-cuts)));
				} catch (Exception e) {
					k = 0;
					break;
				}
				if(free >= k) {
					k = 0;
					break;
				}
				toCut += (1L<<cuts);
				numSquares += (1L<<(cuts+1));
			}
			if(k == 0) {
				out.printf("YES %d\n", n-cuts);
			}
			else {
				out.printf("NO\n");
			}
		}

		out.close();
	}

	long getVal(int n) {
		if(n > 31) return oo;
		long last = 0, cur = 0;
		for(int i = 1; i <= n; i++) {
			cur = 1 + 4*last;
			last = cur;
		}
		return cur;
	}

	class FastScanner {
		public int BS = 1<<16;
		public char NC = (char)0;
		byte[] buf = new byte[BS];
		int bId = 0, size = 0;
		char c = NC;
		double num = 1;
		BufferedInputStream in;

		public FastScanner() {
			in = new BufferedInputStream(System.in, BS);
		}

		public FastScanner(String s) throws FileNotFoundException {
			in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
		}

		public char nextChar(){
			while(bId==size) {
				try {
					size = in.read(buf);
				}catch(Exception e) {
					return NC;
				}
				if(size==-1)return NC;
				bId=0;
			}
			return (char)buf[bId++];
		}

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

		public long nextLong() {
			num=1;
			boolean neg = false;
			if(c==NC)c=nextChar();
			for(;(c<'0' || c>'9'); c = nextChar()) {
				if(c=='-')neg=true;
			}
			long res = 0;
			for(; c>='0' && c <='9'; c=nextChar()) {
				res = (res<<3)+(res<<1)+c-'0';
				num*=10;
			}
			return neg?-res:res;
		}

		public double nextDouble() {
			double cur = nextLong();
			return c!='.' ? cur:cur+nextLong()/num;
		}

		public String next() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c>32) {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public String nextLine() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c!='\n') {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public boolean hasNext() {
			if(c>32)return true;
			while(true) {
				c=nextChar();
				if(c==NC)return false;
				else if(c>32)return true;
			}
		}

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

	}

}


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

public class code {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int q = sc.nextInt();
		long[] d = new long[30];
		d[0] = 1;
		for(int i=1;i<30;i++) d[i] = d[i-1]*4;
		for(int z=0;z<q;z++){
		    long r = 0;
		    long n = sc.nextLong();
		    long k = sc.nextLong();
		    long c = 1;
		    while(k>0&&n>=1){
		        if(k<=r) {
		            k=0;
		            break;
		        }
		        n--;
		        k-=c;
		        if(k<=0) break;

		        if(n>30) {
		            k=0;
		            break;
		        }
		        for(int i=0;i<(int)n;i++){
		            r += d[i]*(c*2-1);
		            if(k<=r) {
		                k=0;
		                break;
		            }
		        }
		        if(k<=r) {
		            k=0;
		            break;
		        }
		        c*=2;
		        c++;
		    }
		    if(k==0) System.out.println("YES "+n);
		    else System.out.println("NO");
		}
	}
}

/*
NO
YES 0
YES 0
NO
NO
YES 999999942
YES 59
YES 63
YES 2
NO
YES 1
YES 1
NO
NO
YES 0
YES 0*/


//package round503;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;

public class B2 {
	Scanner in;
	PrintWriter out;
	String INPUT = "";

	// 12123432
	// 12343212

	int qc = 0;
	int n;

	int[] table;

	int val(int x)
	{
		if(table[x] != Integer.MIN_VALUE)return table[x];
		if(qc > 60)throw new RuntimeException();
		out.println("? " + (x+1));
		out.flush();
		table[x] = ni();

		if(table[x] == table[(x+table.length/2) % table.length]){
			if(x >= n/2)x -= n/2;
			out.println("! " + (x+1));
			out.flush();
			throw new IllegalStateException();
		}
		return table[x];
	}

	void solve()
	{
		n = ni();
		if(n % 4 != 0){
			out.println("! -1");
			out.flush();
			return;
		}
		table = new int[n];
		Arrays.fill(table, Integer.MIN_VALUE);
		Random gen = new Random(1);
		try{
			outer:
			while(true){
				int pu = gen.nextInt(n);
				int pd = (pu+n/2)%n;
				int pl = (pu + gen.nextInt(n/2-1)+1)%n;
				int pr = (pl+n/2)%n;

				int vu = val(pu), vd = val(pd);
				int vl = val(pl), vr = val(pr);
				if(cross(vu, vl, vd, vr)){
				}else if(cross(vu, vr, vd, vl)){
					int npu = pr, npl = pu;
					int npd = pl, npr = pd;
					pu = npu; pl = npl;
					pd = npd; pr = npr;
					vu = val(pu);
					vl = val(pl);
					vd = val(pd);
					vr = val(pr);
				}else{
					continue outer;
				}
				// u-l d-r
				while(true){
					int pul = h(pu, pl, n);
					int vul = val(pul);
					int pdr = h(pd, pr, n);
					int vdr = val(pdr);
					if(cross(vul, vu, vdr, vd)){
						pl = pul; vl = vul;
						pr = pdr; vr = vdr;
					}else{
						pu = pul; vu = vul;
						pd = pdr; vd = vdr;
					}
				}
			}
		}catch(IllegalStateException e)
		{
		}
	}

	int h(int a, int b, int n)
	{
		if(a > b){
			b += n;
		}
		int u = (a+b)/2;
		if(u >= n)u -= n;
		return u;
	}

	boolean cross(int a, int b, int c, int d)
	{
		return Integer.signum(c-a) != Integer.signum(d-b);
	}

	void run() throws Exception
	{
		in = oj ? new Scanner(System.in) : new Scanner(INPUT);
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		tr(System.currentTimeMillis()-s+"ms");
	}

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

	int ni() { return Integer.parseInt(in.next()); }
	long nl() { return Long.parseLong(in.next()); }
	double nd() { return Double.parseDouble(in.next()); }
	boolean oj = System.getProperty("ONLINE_JUDGE") != null;
	void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}
//


import java.util.*;
import java.io.*;
import java.lang.*;
import java.math.*;
public class B {
    public static PrintWriter out;
    public static BufferedReader bf;
    public static int n;
    public static int[] a;
    public static void main(String[] args) throws Exception {
        bf = new BufferedReader(new InputStreamReader(System.in));
        // Scanner scan = new Scanner(System.in);
        out = new PrintWriter(new OutputStreamWriter(System.out));
        n = Integer.parseInt(bf.readLine());
        a = new int[n];
        Arrays.fill(a, Integer.MAX_VALUE);
        if((n/2) % 2 != 0) {
          out.println("! " + (-1));
          out.flush();
          out.close(); System.exit(0);
        }

        ask(0);
        ask(opp(0));

        int low = 0;
        int high = opp(0);
        while(true) {
          int test = (low + high)/2;
          ask(test);
          ask(opp(test));
          int l_1 = a[low];
          int l_2 = a[test];
          int r_1 = a[opp(low)];
          int r_2 = a[opp(test)];
          if(1L*(l_1 - r_1)*(l_2 - r_2) < 0L) {
            high = test;
          }
          else low = test;
        }

        // StringTokenizer st = new StringTokenizer(bf.readLine());
        // int[] a = new int[n]; for(int i=0; i<n; i++) a[i] = Integer.parseInt(st.nextToken());
        // int n = Integer.parseInt(st.nextToken());
        // int n = scan.nextInt();

        //out.close(); System.exit(0);
    }
    public static int ask(int i) throws Exception { // 0 thru n-1;
      out.println("? " + (i+1));
      out.flush();
      int k = Integer.parseInt(bf.readLine());
      a[i] = k;
      if(a[i] == a[opp(i)]) {
        out.println("! " + (i+1));
        out.flush();
        out.close(); System.exit(0);
      }

      return k;
    }
    public static int opp(int k) {
      return ((k + n/2) % n);
    }
}


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

public class CFB {
    static int n;
    static FastScanner in;
    public static void main(String[] args) throws Exception {
        in = new FastScanner(System.in);
        n = in.nextInt();
        int a = query(1);
        if(((a % 2)+2) % 2== 1){
            System.out.println("! -1");
            return;
        }
        if(a == 0){
            System.out.println("! 1");
            return;
        }
        bins(1 , n/2 + 1 , a , -a);
    }
    static void bins(int lo , int hi , int losign , int hisign){
        int mid = (lo + hi)/2;
        int k = query(mid);
        if(k == 0){
            System.out.println("! " + mid);
            System.exit(0);
        }
        if(k > 0 && losign > 0 || k < 0 && losign < 0){
            bins(mid , hi , k , hisign);
        }
        else {
            bins(lo , mid , losign , k);
        }

    }
    static int query(int i){
        System.out.println("? " + i);
        int a1 = in.nextInt();
        System.out.println("? " + ((i + (n/2)) > n ? (i - (n/2)) : (i + (n/2))));
        int a2 = in.nextInt();
        return a1 - a2;
    }

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

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

        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++];
        }

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

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

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

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

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

        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();
        }

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


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 lewin
 */
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);
        BTheHat solver = new BTheHat();
        solver.solve(1, in, out);
        out.close();
    }

    static class BTheHat {
        InputReader in;
        OutputWriter out;
        int n;

        int ask(int student) {
            student %= n;
            out.println("? " + (student + 1));
            out.flush();
            return in.nextInt();
        }

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            this.in = in;
            this.out = out;

            n = in.nextInt();
            int a = ask(0), b = ask(n / 2);
            if ((a + b) % 2 != 0) {
                out.println("! -1");
                out.flush();
                return;
            }
            if (a == b) {
                out.println("! 1");
                out.flush();
                return;
            }

            int lo = 0, hi = n / 2;
            while (lo < hi) {
                int mid = (lo + hi) / 2;
                int f1 = ask(mid), f2 = ask(mid + n / 2);
                if (f1 == f2) {
                    out.println("! " + (mid + 1));
                    return;
                }
                if ((a > b) == (f1 > f2)) {
                    lo = mid + 1;
                } else {
                    hi = mid - 1;
                }
            }
            out.println("! " + (lo + 1));
            out.flush();
        }

    }

    static class InputReader {
        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 (this.numChars == -1) {
                throw new InputMismatchException();
            } else {
                if (this.curChar >= this.numChars) {
                    this.curChar = 0;

                    try {
                        this.numChars = this.stream.read(this.buf);
                    } catch (IOException var2) {
                        throw new InputMismatchException();
                    }

                    if (this.numChars <= 0) {
                        return -1;
                    }
                }

                return this.buf[this.curChar++];
            }
        }

        public int nextInt() {
            int c;
            for (c = this.read(); isSpaceChar(c); c = this.read()) {
                ;
            }

            byte sgn = 1;
            if (c == 45) {
                sgn = -1;
                c = this.read();
            }

            int res = 0;

            while (c >= 48 && c <= 57) {
                res *= 10;
                res += c - 48;
                c = this.read();
                if (isSpaceChar(c)) {
                    return res * sgn;
                }
            }

            throw new InputMismatchException();
        }

        public static boolean isSpaceChar(int c) {
            return c == 32 || c == 10 || c == 13 || c == 9 || c == -1;
        }

    }

    static 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 println(Object... objects) {
            print(objects);
            writer.println();
        }

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

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

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.Reader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class TaskB {
        int n;
        MyInput in;
        PrintWriter out;

        public void solve(int testNumber, MyInput in, PrintWriter out) {
            this.in = in;
            this.out = out;

            n = in.nextInt();

            if (n / 2 % 2 == 1) {
                answer(-1);
                return;
            }

            int low = 0, high = n / 2;
            int diff = query(low + n / 2) - query(low);
            while (diff != 0) {
                int mid = (low + high) / 2;
                int d = query(mid + n / 2) - query(mid);
                if (d == 0 || diff > 0 == d > 0) {
                    diff = d;
                    low = mid;
                } else {
                    high = mid;
                }
            }
            answer(low);
        }

        int query(int i) {
            out.println("? " + (i % n + 1));
            out.flush();
            return in.nextInt();
        }

        void answer(int i) {
            out.println("! " + (i < 0 ? i : (i % n + 1)));
        }

    }

    static class MyInput {
        private final BufferedReader in;
        private static int pos;
        private static int readLen;
        private static final char[] buffer = new char[1024 * 8];
        private static char[] str = new char[500 * 8 * 2];
        private static boolean[] isDigit = new boolean[256];
        private static boolean[] isSpace = new boolean[256];
        private static boolean[] isLineSep = new boolean[256];

        static {
            for (int i = 0; i < 10; i++) {
                isDigit['0' + i] = true;
            }
            isDigit['-'] = true;
            isSpace[' '] = isSpace['\r'] = isSpace['\n'] = isSpace['\t'] = true;
            isLineSep['\r'] = isLineSep['\n'] = true;
        }

        public MyInput(InputStream is) {
            in = new BufferedReader(new InputStreamReader(is));
        }

        public int read() {
            if (pos >= readLen) {
                pos = 0;
                try {
                    readLen = in.read(buffer);
                } catch (IOException e) {
                    throw new RuntimeException();
                }
                if (readLen <= 0) {
                    throw new MyInput.EndOfFileRuntimeException();
                }
            }
            return buffer[pos++];
        }

        public int nextInt() {
            int len = 0;
            str[len++] = nextChar();
            len = reads(len, isSpace);
            int i = 0;
            int ret = 0;
            if (str[0] == '-') {
                i = 1;
            }
            for (; i < len; i++) ret = ret * 10 + str[i] - '0';
            if (str[0] == '-') {
                ret = -ret;
            }
            return ret;
        }

        public char nextChar() {
            while (true) {
                final int c = read();
                if (!isSpace[c]) {
                    return (char) c;
                }
            }
        }

        int reads(int len, boolean[] accept) {
            try {
                while (true) {
                    final int c = read();
                    if (accept[c]) {
                        break;
                    }
                    if (str.length == len) {
                        char[] rep = new char[str.length * 3 / 2];
                        System.arraycopy(str, 0, rep, 0, str.length);
                        str = rep;
                    }
                    str[len++] = (char) c;
                }
            } catch (MyInput.EndOfFileRuntimeException e) {
            }
            return len;
        }

        static class EndOfFileRuntimeException extends RuntimeException {
        }

    }
}


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

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

    static class BTheHat {
        PrintWriter out;
        InputReader in;
        int n;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            this.out = out;
            this.in = in;
            n = in.NextInt();
            int desiredPair = -1;
            int result = query(1);
            if (result != 0) {
                int l = 2, r = 1 + n / 2;
                while (l < r) {
                    int m = (l + r) / 2;
                    int mRes = query(m);
                    if (mRes == 0) {
                        desiredPair = m;
                        break;
                    } else if (mRes == result) {
                        l = m + 1;
                    } else {
                        r = m;
                    }
                }
            } else {
                desiredPair = 1;
            }
            out.println("! " + desiredPair);
        }

        private int query(int i) {
            int iV = queryValue(i);
            int iN2V = queryValue(i + n / 2);
            if (iV < iN2V) {
                return -1;
            } else if (iV > iN2V) {
                return 1;
            }
            return 0;
        }

        private int queryValue(int i) {
            out.println("? " + i);
            out.flush();
            return in.NextInt();
        }

    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

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

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

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

    }
}


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

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

    static class TaskB {
        FastReader in;
        PrintWriter out;
        int n;

        public void solve(int testNumber, FastReader in, PrintWriter out) {
            this.in = in;
            this.out = out;
            n = in.nextInt();
            if (n % 4 != 0) {
                out.println("! -1");
                return;
            }
            int low = 0;
            int high = n >> 1;
            int fSign = Integer.signum(BValue(low));
            if (fSign == 0) {
                out.println("! " + (low + 1));
                return;
            }
            while (high - low > 1) {
                int mid = (high + low) >> 1;
                int mSign = Integer.signum(BValue(mid));
                if (mSign == 0) {
                    out.println("! " + (mid + 1));
                    return;
                }
                if (mSign == -fSign) {
                    high = mid;
                } else {
                    low = mid;
                }
            }
            out.println("! -1");
        }

        public int BValue(int index) {
            out.println("? " + (index + 1));
            out.flush();
            int f = in.nextInt();
            out.println("? " + (index + 1 + (n >> 1)));
            out.flush();
            int s = in.nextInt();
            return f - s;
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[8192];
        private int curChar;
        private int pnumChars;

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

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

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

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

    }
}


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

public class B {
	static PrintWriter out = new PrintWriter(System.out);
	static FS in;

	static int N;
	static final boolean debug = false;
	static int inp[] = new int[] {1,2,3,2,1,0};
	public static void main(String[] args) {
		in = new FS();
		if(!debug) N = in.nextInt();
		else N = inp.length;
		int x = solve(0, N/2-1, N/2, N-1);
		out.println("! "+(x+1));
		out.flush();
		out.close();
	}

	static int solve(int l1, int r1, int l2, int r2) {
		int sz = r1-l1+1;
		if(sz <= 0) return -2;
		int a1 = query(l1);
		int a2 = query(l2);
		if(a1 == a2) return l1;

		if(sz == 1) return -2;

		int b1 = query(l1+sz/2);
		int b2 = query(l2+sz/2);
		if(b1 == b2) return l1 + sz/2;

		if(sz == 2) return -2;

		int d1 = a2-a1;
		int d2 =  b2-b1;
		if((d1 < 0 && d2 > 0) || (d1 > 0 && d2 < 0)) {
			return solve(l1+1, l1 + sz/2 - 1, l2+1, l2 + sz/2 - 1);
		}
		else {
			return solve(l1 + sz/2 + 1, r1, l2 + sz/2 + 1, r2);
		}
	}

	static int query(int a) {
		out.println("? "+(a+1));
		out.flush();
		if(debug) return inp[a];
		else return in.nextInt();
	}

	static class FS{
		BufferedReader br;
		StringTokenizer st;
		public FS() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		String next() {
			while(st == null || !st.hasMoreElements()) {
				try {st = new StringTokenizer(br.readLine());}
				catch(Exception e) { throw null;}
			}
			return st.nextToken();
		}
		int nextInt() { return Integer.parseInt(next());}
		double nextDouble() { return Double.parseDouble(next());}
		long nextLong() { return Long.parseLong(next());}
		int[] NIA(int n) {
			int r[] = new int[n];
			for(int i = 0; i < n; i++) r[i] = nextInt();
			return r;
		}
		long[] NLA(int n) {
			long r[] = new long[n];
			for(int i = 0; i < n; i++) r[i] = nextLong();
			return r;
		}
		char[][] grid(int r, int c){
			char res[][] = new char[r][c];
			for(int i = 0; i < r; i++) {
				char l[] = next().toCharArray();
				for(int j = 0; j < c; j++) {
					res[i][j] = l[j];
				}
			}
			return res;
		}
	}

}


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

public class B {

	public static void main(String[] args) throws IOException {
		MyScanner sc = new MyScanner();
		PrintWriter out = new PrintWriter(System.out);
		int N = sc.nextInt();
		if (N / 2 % 2 == 1) {
			output(-1, out);
		} else {
			int half = N / 2;
			int l = 1, r = half;
			int first = query(half, out, sc);
			int next = query(2 * half, out, sc);
			if (first == next) {
				output(half, out);
				return;
			}
			boolean less = first < next;
			while (l + 1 < r) {
				int med = (l + r) / 2;
				first = query(med, out, sc);
				next = query(med + half, out, sc);
				if (first == next) {
					output(med, out);
					return;
				} else if (first < next == less) {
					r = med;
				} else {
					l = med + 1;
				}
			}
			output(l, out);
		}
	}

	static int query(int pos, PrintWriter out, MyScanner sc) {
		out.println("? " + pos);
		out.flush();
		return sc.nextInt();
	}

	static void output(int pos, PrintWriter out) {
		out.println("! " + pos);
		out.flush();
	}

	static class MyScanner {
		private BufferedReader br;
		private StringTokenizer tokenizer;

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

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(br.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());
		}
	}
}


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

public class B {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Task solver = new Task();
		solver.solve(1, in, out);
		out.close();
	}

	static class Task {
		int n = 0;
		int query(int p, InputReader in) {
			p %= n;
			if (p <= 0) p += n;
			System.out.println("? " + p);
			System.out.flush();
			int x = in.nextInt();
			return x;
		}
		public void solve(int testNumber, InputReader in, PrintWriter out) {
			n = in.nextInt();
			if (n % 4 != 0) {
				out.println("! -1");
				return;
			}
			int p = query(0, in);
			int q = query(n / 2, in);
			int l = 0;
			int r = n / 2;
			if (p == q) {
				out.println("! " + (n / 2));
				return;
			}
			while (l + 1 < r) {
				int mid = (l + r) / 2;
				int u = query(mid, in);
				int v = query(mid + n / 2, in);
				if (u == v) {
					out.println("! " + (mid + n / 2));
					return;
				}
				if ((p < q) == (u < v)) {
					l = mid;
				} else {
					r = mid;
				}
			}
		}
	}

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

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

		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());
		}

	}
}


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

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

    static class TaskB {
        int N;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            N = in.nextInt();
            int low = 1;
            int lowVal = getval(1, out, in);
            int high = N / 2 + 1;
            int highVal = -lowVal;
            if (Math.abs(lowVal) % 2 == 1) {
                out.println("! -1");
                out.flush();
            } else {
                while (low < high) {
                    int mid = (low + high) / 2;
                    int a = getval(mid, out, in);
                    if (Integer.signum(a) == 0) {
                        out.println("! " + mid);
                        out.flush();
                        return;
                    } else {
                        if (Integer.signum(a) == Integer.signum(lowVal)) {
                            low = mid + 1;
                        } else {
                            high = mid;
                        }
                    }
                }
                out.println("! " + low);
                out.flush();
            }
        }

        int getval(int i, PrintWriter out, InputReader in) {
            out.println("? " + i);
            out.flush();
            int a = in.nextInt();
            out.println("? " + (i + N / 2));
            out.flush();
            int b = in.nextInt();
            return a - b;
        }

    }

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

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

        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());
        }

    }
}


import java.io.*;
import java.util.*;
public class Main {
	final static int MAXN = 100005;
	static int n;
	static Scanner cin;
	static int[] a;
	static boolean[] used;
	public static int Query(int x) {
		System.out.print("? ");
		System.out.println(x);
		System.out.flush();
		int a = cin.nextInt();
		return a;
	}
	public static int Q(int x) {
		if(used[x]) return a[x];
		used[x] = true;
		a[x] = Query(x) - Query(x + n / 2);
		if(a[x] == 0) {
			System.out.print("! ");
			System.out.println(x);
			System.out.flush();
			cin.close();
			System.exit(0);
		}
		return a[x];
	}
	public static void main(String[] args) {
		cin = new Scanner(System.in);
		n = cin.nextInt();
		a = new int[MAXN];
		used = new boolean[MAXN];
		if(n % 4 != 0) {
			System.out.println("! -1\n");
			System.out.flush();
			cin.close();
			return;
		}
		int l = 1, r = n / 2, mid;
		while(l <= r) {
			mid = (l + r) / 2;
			int x = Q(mid);
			if(Q(l) * x < 0) {
				r = mid - 1;
			} else if(x * Q(r) < 0) {
				l = mid + 1;
			}
		}
		System.out.println("! -1\n");
		System.out.flush();
		cin.close();
	}
}


import java.util.*;
import java.io.*;
import java.math.*;
public class Main
{
    static class Reader
    {
        private InputStream mIs;private byte[] buf = new byte[1024];private int curChar,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 s(){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 long l(){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 i(){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 double d() throws IOException {return Double.parseDouble(s()) ;}
        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; }
        public int[] arr(int n){int[] ret = new int[n];for (int i = 0; i < n; i++) {ret[i] = i();}return ret;}
    }

           //       |----|       /\      |    |   -----   |
           //       |   /       /  \     |    |     |     |
           //       |--/       /----\    |----|     |     |
           //       |   \     /      \   |    |     |     |
           //       |    \   /        \  |    |   -----   -------

    public static void main(String[] args)throws IOException
    {
        PrintWriter out= new PrintWriter(System.out);
        Reader sc=new Reader();
        int n=sc.i();
        System.out.println("? "+1);
        int a=sc.i();
        System.out.println("? "+(1+n/2));
        int b=sc.i();
        if(a==b)
        {
            System.out.println("! "+1);
            System.exit(0);
        }
        int inv=0;
        if(a>b)
        inv=1;

        int low=2;
        int high=n/2;
        int q=0;
        while(low<=high)
        {
            if(q==60)
            break;
            int mid=(low+high)/2;
            System.out.println("? "+mid);
            a=sc.i();
            System.out.println("? "+(mid+n/2));
            b=sc.i();
            if(a==b)
            {
                System.out.println("! "+mid);
                System.exit(0);
            }
            else if(a<b)
            {
                if(inv==0)
                low=mid+1;
                else
                high=mid-1;
            }

            else
            {
                if(inv==0)
                high=mid-1;
                else
                low=mid+1;
            }
            q++;
        }
        System.out.println("! -1");
        out.flush();
    }
}


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

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

    static class TaskB {
        FastReader in;
        PrintWriter out;
        int n;

        public void solve(int testNumber, FastReader in, PrintWriter out) {
            this.in = in;
            this.out = out;
            n = in.nextInt();
            if (n % 4 != 0) {
                out.println("! -1");
                return;
            }
            int low = 0;
            int high = n >> 1;
            if (BValue(low) == 0) {
                out.println("! " + (low + 1));
                return;
            }
            int fSign = Integer.signum(BValue(low));
            while (high - low > 1) {
                int mid = (high + low) >> 1;
                int mSign = Integer.signum(BValue(mid));
                if (mSign == 0) {
                    out.println("! " + (mid + 1));
                    return;
                }
                if (mSign == -fSign) {
                    high = mid;
                } else {
                    low = mid;
                }
            }
            out.println("! -1");
        }

        public int BValue(int index) {
            out.println("? " + (index + 1));
            out.flush();
            int f = in.nextInt();
            out.println("? " + (index + 1 + (n >> 1)));
            out.flush();
            int s = in.nextInt();
            return f - s;
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[8192];
        private int curChar;
        private int pnumChars;

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

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

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

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

    }
}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;

public class Div1_503B {

	public static void main(String[] args) throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter printer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		int N = Integer.parseInt(reader.readLine());
		printer.println("? 1");
		printer.flush();
		int v1 = Integer.parseInt(reader.readLine());

		printer.println("? " + (1 + N / 2));
		printer.flush();
		int v2 = Integer.parseInt(reader.readLine());

		if ((v1 + v2) % 2 != 0) {
			printer.println("! -1");
			printer.close();
			return;
		}

		if (v1 == v2) {
			printer.println("! 1");
			printer.close();
			return;
		}
		boolean less = v1 < v2;

		int low = 1;
		int high = (1 + N / 2);

		while (low != high) {
			int mid = (low + high) >> 1;

			printer.println("? " + mid);
			printer.flush();
			int r1 = Integer.parseInt(reader.readLine());

			int q2 = (mid + N / 2);
			if (q2 > N) {
				q2 -= N;
			}
			printer.println("? " + q2);
			printer.flush();
			int r2 = Integer.parseInt(reader.readLine());

			if (r1 == r2) {
				printer.println("! " + mid);
				printer.close();
				return;
			}

			if (r1 < r2 == less) {
				low = mid + 1;
			} else {
				high = mid - 1;
			}
		}
		printer.println("! " + low);
		printer.close();
		return;
	}
}


//package contests.CF1019;

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

public class B {

    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);

        int n = sc.nextInt();
        int half = n/2;
        pw.println("? 1");
        pw.flush();
        int a = sc.nextInt();
        pw.println("? " + (1+half));
        pw.flush();
        int b = sc.nextInt();
        if(a - b == 0){
            pw.println("! 1");
        }
        else
        if((a - b)%2 != 0)
        {
            pw.println("! -1");
        }else{
            boolean greater = a > b;
            int lo = 1;
            int hi = half;

            boolean ans = false;
            while(lo <= hi){
                int mid = (lo + hi) /2;
                pw.println("? " + mid);
                pw.flush();
                a = sc.nextInt();
                pw.println("? " + (mid+half));
                pw.flush();
                b = sc.nextInt();

                if(a == b){
                    pw.println("! " + mid);
                    ans = true;
                    break;
                }

                if(a > b != greater){
                    hi = mid-1;
                }else{
                    lo = mid+1;
                    greater = a>b;
                }
            }

            if(!ans){
                pw.println("! -1");
            }

        }

        pw.flush();
        pw.close();
    }

    static int[][] packD(int n, int[] from, int[] to) {
        int[][] g = new int[n][];
        int[] p = new int[n];
        for (int f : from) if(f != -1) p[f]++;
        for (int i = 0; i < n; i++) g[i] = new int[p[i]];
        for (int i = 0; i < from.length; i++) if(from[i] != -1) {g[from[i]][--p[from[i]]] = to[i];}
        return g;
    }

    static void shuffle(int[] a)
    {
        int n = a.length;
        for(int i = 0; i < n; i++)
        {
            int r = i + (int)(Math.random() * (n - i));
            int tmp = a[i];
            a[i] = a[r];
            a[r] = tmp;
        }
    }

    static class Scanner
    {
        StringTokenizer st; BufferedReader br;
        public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}
        public Scanner(String s) throws FileNotFoundException {	br = new BufferedReader(new FileReader(new File(s)));}
        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 boolean ready() throws IOException {return br.ready();}
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Random;
import java.util.StringTokenizer;

public class Solution{

	static FastScanner fs = new FastScanner();
	static PrintWriter out = new PrintWriter(System.out);
	static int n, d;

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

//    	FastScanner fs = new FastScanner();
//    	PrintWriter out = new PrintWriter(System.out);

    	int tt = 1;
    	while(tt-->0) {

    		n = fs.nextInt();
    		int l = 1, r = 1 + n/2;

    		d = getB(l);
    		if(d%2!=0) {
    			out.println("! -1");
    			out.flush();
    			return;
    		}

    		if(d==0) {
    			out.println("! 1");
    			out.flush();
    			return;
    		}

    		while(l<r) {
    			int mid = (l+r)/2;
    			if(check(mid)) {
    				l = mid + 1;
    			}
    			else {
    				r = mid;
    			}
    			int f = 1;
    		}

    		out.println("! "+l);

    	}

    	out.close();

    }

    static boolean check(int i) {
    	int k = getB(i);
    	if(sig(d)==sig(k)) {
    		return true;
    	}
    	return false;
    }

    static int getB(int i) {
    	out.println("? "+i);
    	out.flush();
    	int x1 = fs.nextInt();
    	int j = i + n/2;
    	if(j>n) j -= n;
    	out.println("? "+j);
    	out.flush();
    	int x2 = fs.nextInt();
    	return x1 - x2;
    }

    static int sig(int x) {
    	if(x>0) return 1;
    	else if(x<0) return -1;
    	return 0;
    }

    static final Random random=new Random();

    static <T> void shuffle(T[] arr) {
    	int n = arr.length;
    	for(int i=0;i<n;i++	) {
    		int k = random.nextInt(n);
    		T temp = arr[k]; arr[k] = arr[i]; arr[i] = temp;
    	}
    }

    static void ruffleSort(int[] a) {
    	int n=a.length;//shuffle, then sort
    	for (int i=0; i<n; i++) {
    		int oi=random.nextInt(n); int temp=a[oi];
    		a[oi]=a[i]; a[i]=temp;
    	}
    	Arrays.sort(a);
    }

    static void ruffleSort(long[] a) {
    	int n=a.length;//shuffle, then sort
    	for (int i=0; i<n; i++) {
    		int oi=random.nextInt(n); long temp=a[oi];
    		a[oi]=a[i]; a[i]=temp;
    	}
    	Arrays.sort(a);
    }

    static void reverse(int[] arr, int l, int r) {
    	for(int i=l;i<l+(r-l)/2;i++){
    		int temp = arr[i]; arr[i] = arr[r-i+l-1]; arr[r-i+l-1] = temp;
    	}
    }

    static void reverse(long[] arr, int l, int r) {
    	for(int i=l;i<l+(r-l)/2;i++){
    		long temp = arr[i]; arr[i] = arr[r-i+l-1]; arr[r-i+l-1] = temp;
    	}
    }

    static <T> void reverse(T[] arr, int l, int r) {
    	for(int i=l;i<l+(r-l)/2;i++) {
    		T temp = arr[i]; arr[i] = arr[r-i+l-1]; arr[r-i+l-1] = temp;
    	}
    }

    static class FastScanner{
    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    	StringTokenizer st = new StringTokenizer("");

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

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

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

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

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

    	public char nextChar() {
    		return next().toCharArray()[0];
    	}
    }

}


import java.io.*;
import java.util.Arrays;
import java.util.Comparator;
import java.util.StringTokenizer;
import java.util.stream.IntStream;

public class B {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));

        Solver solver = new Solver();
        solver.solve(in, out);
        out.close();
    }

    static class Solver {
        int n;
        int n2;
        InputReader in;
        PrintWriter out;

        public void solve(InputReader in, PrintWriter out) {
            this.in = in;
            this.out = out;
            n = in.readInt();
            n2 = n/2;

            int res = find();
            out.print("! ");
            out.println(res);
        }

        public int find() {
            if (n%4 != 0) return -1;
            int c = compare(0);
            if (c == 0) return 1;
            int s = 1;
            int f = n2-1;
            if (c > 0) {
                s = n2+1;
                f = n-1;
            }
            while (s <= f) {
                int m = (s+f)/2;
                int v = compare(m);
                if (v == 0) return m+1;
                else if (v < 0) s = m+1;
                else f = m-1;
            }
            return -1;
        }

        public int compare(int z) {
            out.print("? ");
            out.println(z+1);
            out.flush();
            int r1 = in.readInt();
            out.print("? ");
            out.println((z+n2)%n+1);
            out.flush();
            int r2 = in.readInt();
            return r1-r2;
        }

    }

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

        public InputReader(InputStream stream) {
            this.reader = new BufferedReader(new InputStreamReader(stream));
        }

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

        public int readInt() {
            return Integer.parseInt(read());
        }

        public long readLong() {
            return Long.parseLong(read());
        }

        public void readIntArrays(int[]... arrays) {
            for (int i = 0; i < arrays[0].length; i++) {
                for (int j = 0; j < arrays.length; j++) {
                    arrays[j][i] = readInt();
                }
            }
        }
    }

}


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 ilyakor
 */
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);
    TaskB solver = new TaskB();
    solver.solve(1, in, out);
    out.close();
  }

  static class TaskB {

    int n;

    public void solve(int testNumber, InputReader in, OutputWriter out) {
      n = in.nextInt();
      int base = calc(in, out, 0);
      if (base == 0) {
        out.printLine("! 1");
        out.flush();
        return;
      }
      if (Math.abs(base) % 2 != 0) {
        out.printLine("! -1");
        out.flush();
        return;
      }
      int down = 0, up = n / 2;
      int sdown = base < 0 ? -1 : 1;
      int sup = up < 0 ? -1 : 1;
      while (up - down > 1) {
        int t = (up + down) / 2;
        int cur = calc(in, out, t);
        if (cur == 0) {
          out.printLine("! " + (t + 1));
          out.flush();
          return;
        }
        int scur = cur < 0 ? -1 : 1;
        if (scur == sdown) {
          down = t;
        } else {
          up = t;
        }
      }
      throw new RuntimeException();
    }

    private int calc(InputReader in, OutputWriter out, int val) {
      out.printLine("? " + (val + 1));
      out.flush();
      int res1 = in.nextInt();
      out.printLine("? " + ((val + n / 2) % n + 1));
      out.flush();
      int res2 = in.nextInt();
      return res1 - res2;
    }

  }

  static 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();
    }

  }

  static class InputReader {

    private InputStream stream;
    private byte[] buffer = new byte[10000];
    private int cur;
    private int count;

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

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

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

    public int readSkipSpace() {
      int c;
      do {
        c = read();
      } while (isSpace(c));
      return c;
    }

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

  }
}


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

public class Main {

    private static final long MOD = 998244353;

    static int[] readArray(int size, InputReader in, boolean subOne) {
        int[] a = new int[size];
        for (int i = 0; i < size; i++) {
            a[i] = in.nextInt() + (subOne ? -1 : 0);
        }
        return a;
    }

    static long[] readLongArray(int size, InputReader in) {
        long[] a = new long[size];
        for (int i = 0; i < size; i++) {
            a[i] = in.nextLong();
        }
        return a;
    }

    static void sortArray(int[] a) {
        Random random = new Random();

        for (int i = 0; i < a.length; i++) {
            int randomPos = random.nextInt(a.length);
            int t = a[i];
            a[i] = a[randomPos];
            a[randomPos] = t;
        }
        Arrays.sort(a);
    }

    public static void main(String[] args) throws FileNotFoundException {
//        InputReader in = new InputReader(new FileInputStream("input.txt"));
//        PrintWriter out = new PrintWriter(new BufferedOutputStream(new FileOutputStream("milkvisits.out")));
//
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));

        int n = in.nextInt();
        if (n / 2 % 2 != 0) {
            out.println("! -1");
            out.flush();
            out.close();
            return;
        }

        int[] a = new int[n];
        Arrays.fill(a, Integer.MAX_VALUE);

        int l1 = 0;
        int r1 = l1 + n / 2;

        int l2 = r1;
        int r2 = n;

        int ans = -1;

        while (true) {
            getValue(in, out, a, l1);
            getValue(in, out, a, r1);

            getValue(in, out, a, l2);
            getValue(in, out, a, r2 % n);

            if (a[l1] == a[l2]) {
                ans = l1;
                break;
            }
            if (a[r1] == a[r2 % n]) {
                ans = r1;
                break;
            }

            int m1 = (l1 + r1) / 2;
            getValue(in, out, a, m1);

            int m2 = (l2 + r2) / 2;
            getValue(in, out, a, m2);

            if (a[m1] == a[m2]) {
                ans = m1;
                break;
            }

            if ((a[l1] <= a[m1] && a[l2] <= a[m2]) || (a[l1] >= a[m1] && a[l2] >= a[m2])) {
                if (a[l1] <= a[l2] && a[m1] >= a[m2]) {
                    r1 = m1;
                    r2 = m2;
                    continue;
                }

                if (a[l1] >= a[l2] && a[m1] <= a[m2]) {
                    r1 = m1;
                    r2 = m2;
                    continue;
                }
            }

            if (a[l1] <= a[m1] && a[l2] >= a[m2] && a[l1] <= a[l2] && a[m1] >= a[m2]){
                r1 = m1;
                r2 = m2;
                continue;
            }

            if (a[l1] >= a[m1] && a[l2] <= a[m2] && a[l1] >= a[l2] && a[m1] <= a[m2]){
                r1 = m1;
                r2 = m2;
                continue;
            }

            l1 = m1;
            l2 = m2;
        }
        out.println("! " + (ans + 1));

        out.close();
    }

    private static void getValue(InputReader in, PrintWriter out, int[] a, int l) {
        if (a[l] == Integer.MAX_VALUE) {
            out.println("? " + (l + 1));
            out.flush();
            a[l] = in.nextInt();
        }
    }

    private static boolean check(long x, long s, long a, List<Long> divA) {
        int ind = binSearchRight(divA, x, 0, divA.size());
        if (ind >= 0 && ind < divA.size()) {
            long y = a / divA.get(ind);
            return y <= s / x;
        }
        return false;
    }

    static int binSearchRight(List<Long> list, long key, int start, int end) {
        int l = start - 1;
        int r = end;
        while (l < r - 1) {
            int m = (l + r) / 2;
            if (list.get(m) <= key) {
                l = m;
            } else {
                r = m;
            }
        }
        return l;
    }

    private static void outputArray(int[] ans, PrintWriter out, boolean addOne) {
        StringBuilder str = new StringBuilder();
        for (int i = 0; i < ans.length; i++) {
            long an = ans[i] + (addOne ? 1 : 0);
            str.append(an).append(' ');
        }
        out.println(str);
    }

    private static void outputArray(List<Integer> ans, PrintWriter out, boolean addOne) {
        StringBuilder str = new StringBuilder();
        for (int j = 0; j < ans.size(); j++) {
            long i = ans.get(j);
            long an = i + (addOne ? 1 : 0);
            str.append(an);
            if (j < ans.size() - 1) {
                str.append(' ');
            }
        }
        out.println(str);
//        out.flush();
    }

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

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

        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 String nextString() {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

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

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

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

        public char nextChar() {
            return next().charAt(0);
        }

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

        private List<Integer>[] readTree(int n) {
            return readGraph(n, n - 1);
        }

        private List<Integer>[] readGraph(int n, int m) {
            List<Integer>[] result = new ArrayList[n];
            for (int i = 0; i < n; i++) {
                result[i] = new ArrayList<>();
            }
            for (int i = 0; i < m; i++) {
                int u = nextInt() - 1;
                int v = nextInt() - 1;
                result[u].add(v);
                result[v].add(u);
            }
            return result;
        }

        private Map<Integer, Long>[] readWeightedGraph(int n, int m) {
            Map<Integer, Long>[] result = new HashMap[n];
            for (int i = 0; i < n; i++) {
                result[i] = new HashMap<>();
            }
            for (int i = 0; i < m; i++) {
                int u = nextInt() - 1;
                int v = nextInt() - 1;
                long w = nextLong();
                result[u].put(v, Math.min(w, result[u].getOrDefault(v, Long.MAX_VALUE)));
                result[v].put(u, Math.min(w, result[v].getOrDefault(u, Long.MAX_VALUE)));
            }
            return result;
        }

    }
}


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

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

    static class TaskB {
        FastReader in;
        PrintWriter out;
        int n;

        public void solve(int testNumber, FastReader in, PrintWriter out) {
            this.in = in;
            this.out = out;
            n = in.nextInt();
            if (n % 4 != 0) {
                out.println("! -1");
                return;
            }
            int low = 0;
            int high = n >> 1;
            if (BValue(low) == 0) {
                out.println("! " + (low + 1));
                return;
            }
            boolean value = BValue(low) > 0;
            while (high - low > 1) {
                int mid = (high + low) >> 1;
                int BVal = BValue(mid);
                if (BVal == 0) {
                    out.println("! " + (mid + 1));
                    return;
                }
                if (value) {
                    if (BVal < 0) {
                        high = mid;
                    } else {
                        low = mid;
                    }
                } else {
                    if (BVal > 0) {
                        high = mid;
                    } else {
                        low = mid;
                    }
                }
            }
            out.println("! -1");
        }

        public int BValue(int index) {
            out.println("? " + (index + 1));
            out.flush();
            int f = in.nextInt();
            out.println("? " + (index + 1 + (n >> 1)));
            out.flush();
            int s = in.nextInt();
            return f - s;
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[8192];
        private int curChar;
        private int pnumChars;

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

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

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

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

    }
}


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

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

    static class DEhabIEsheOdnaOcherednayaZadachaNaXor {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int c = 0;
            int d = 0;

            int prevSign = 0;
            int nextSign;
            boolean zeroOut = true;
            for (int i = 29; i >= 0; i--) {
                if (zeroOut) {
                    print(c, d, out);
                    prevSign = read(in);
                }

                print((1 << i) | c, (1 << i) | d, out);
                nextSign = read(in);

                if (prevSign == nextSign) {
                    zeroOut = false;

                    print((1 << i) | c, d, out);
                    nextSign = read(in);

                    if (nextSign < 0) {
                        c = (1 << i) | c;
                        d = (1 << i) | d;
                    }
                } else {
                    zeroOut = true;

                    if (nextSign < 0) c = (1 << i) | c;
                    else d = (1 << i) | d;
                }
            }

            out.printf("! %d %d", c, d);
            out.flush();
        }

        private void print(int c, int d, PrintWriter out) {
            out.printf("? %d %d\n", c, d);
            out.flush();
        }

        private int read(InputReader in) {
            return in.nextInt();
        }

    }

    static class InputReader {
        private final BufferedReader reader;
        private StringTokenizer tokenizer;

        public InputReader(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

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

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

        public String readLine() {
            String line;
            try {
                line = reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            return line;
        }

    }
}

1088_D. Ehab and another another xor problem


import java.util.*;
public class mad{

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int cura = 0,curb = 0;
        int ver;
        System.out.println("? 0 0");
        System.out.flush();
        ver = sc.nextInt();
        for(int i=29;i>=0;i--){
            System.out.println("? "+(cura+(1<<i))+" "+curb);
            System.out.flush();
            int temp1 = sc.nextInt();
            System.out.println("? "+cura+" "+(curb+(1<<i)));
            System.out.flush();
            int temp2 = sc.nextInt();
            if(temp1!=temp2){
                if(temp2==1){
                    cura += (1<<i);
                    curb += (1<<i);
                }
            }
            else{
                if(ver==1) cura += (1<<i);
                if(ver==-1) curb += (1<<i);

                ver = temp1;
            }
        }
        System.out.println("! "+cura+" "+curb);
    }

}


import java.util.*;
import java.io.*;
public class code{
    public static void main(String[] args) throws IOException{
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int ok,ok2;
        int va,vb;
        va = 0;
        vb = 0;
        out.println("? "+va+" "+vb);
        out.flush();
        ok = sc.nextInt();
        for(int i=29;i>=0;i--){
            if(ok==0){
                va += (1<<i);
                out.println("? "+va+" "+vb);
                out.flush();
                ok2 = sc.nextInt();
                if(ok2==1){
                    va -= (1<<i);
                }else{
                    vb += (1<<i);
                }
            }else{
                va += (1<<i);
                vb += (1<<i);
                out.println("? "+va+" "+vb);
                out.flush();
                ok2 = sc.nextInt();
                if(ok==ok2){
                    vb -= (1<<i);
                    out.println("? "+va+" "+vb);
                    out.flush();
                    ok2 = sc.nextInt();
                    if(ok2==1){
                        va -= (1<<i);
                    }else{
                        vb += (1<<i);
                    }
                }else{
                    if(ok==1){
                        vb -= (1<<i);
                        out.println("? "+va+" "+vb);
                        out.flush();
                        ok = sc.nextInt();
                    }
                    else {
                        va -= (1<<i);
                        out.println("? "+va+" "+vb);
                        out.flush();
                        ok = sc.nextInt();
                    }
                }
            }
        }
        out.println("! "+va+" "+vb);
        out.flush();
    }
}


import java.util.*;

public class ehab4 {
    public static void main( String[] args ) {
        Scanner in = new Scanner( System.in );
	int a = 0, b = 0;
	System.out.println( "? 0 0 " );
	System.out.flush();
	int c = in.nextInt();
	for ( int i = 29; i >= 0; i-- ) {
	    System.out.println( "? " + ( a + ( 1 << i ) ) + " " + b );
	    System.out.flush();
	    int q1 = in.nextInt();
	    System.out.println( "? " + a + " " + ( b + ( 1 << i ) ) );
	    System.out.flush();
	    int q2 = in.nextInt();
	    if ( q1 == q2 ) {
		if ( c == 1 )
		    a += ( 1 << i );
		else if ( c == -1 )
		    b += ( 1 << i );
		c = q1;
	    }
	    else if ( q1 == -1 ) {
		a += ( 1 << i );
		b += ( 1 << i );
	    }
	    else if ( q1 == -2 )
		return;
	}
	System.out.println( "! " + a + " " + b );
	System.out.flush();
    }
}


import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class EhabAndAnotherAnotherXorProblem implements Closeable {

  private InputReader in = new InputReader(System.in);
  private PrintWriter out = new PrintWriter(System.out);

  public void solve() {
    int initial = ask(0, 0);
    int a = 0, b = 0;
    if (initial == 0) {
      for (int i = 0; i < 30; i++) {
        int response = ask(1 << i, 0);
        if (response == -1) {
          a |= (1 << i);
        }
      }
      b = a;
    } else {
      for (int i = 29; i >= 0; i--) {
        int response = ask(a | (1 << i), b | (1 << i));
        if (response != initial) {
          if (response == 1) {
            b |= (1 << i);
          } else {
            a |= (1 << i);
          }
          initial = ask(a, b);
        } else {
          response = ask(a | (1 << i), b);
          if (response == -1) {
            a |= (1 << i);
            b |= (1 << i);
          }
        }

      }
    }
    answer(a, b);
  }

  private int ask(int c, int d) {
    out.printf("? %d %d\n", c, d);
    out.flush();
    return in.ni();
  }

  private void answer(int a, int b) {
    out.printf("! %d %d\n", a, b);
    out.flush();
  }

  @Override
  public void close() throws IOException {
    in.close();
    out.close();
  }

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

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

    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 ni() {
      return Integer.parseInt(next());
    }

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

    public void close() throws IOException {
      reader.close();
    }
  }

  public static void main(String[] args) throws IOException {
    try (EhabAndAnotherAnotherXorProblem instance = new EhabAndAnotherAnotherXorProblem()) {
      instance.solve();
    }
  }
}


import java.util.Scanner;
import java.io.*;
import java.util.*;
public class ReallyBigNumbers817c {
     static long sd(String s) {
        long c = 0;
        for (int i = 0; i < s.length(); i++) {
            c += s.charAt(i);
        }
        return c - s.length() * 0x30;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        long n = in.nextLong();
        long s = in.nextLong(); // number
         // level -- > (n + 8) / 9 * 9; --- > s
        long i = (s/10+1)*10 ;
        if (n<10||n-sd(n+"")<s) {
            System.out.println(0);
            return;
        }
        while(!(i-sd(i+"")>=s)){
        i+=10;

        }
        System.out.println(n-i+1);

    }

	}


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

public class ReallyBigNumbers1
{

    public static void main(String[] args) throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        PrintWriter out = new PrintWriter(System.out);
        long n = Long.parseLong(st.nextToken());
        long s = Long.parseLong(st.nextToken());

        int r = 0 ;

        long l = 0L ;
        long u = n ;

        if(  (l-sumDigits(l)< s )  && (u-sumDigits(u)< s ) )
        {
            out.println(0);
            out.flush();
            out.close();
            return ;
        }

        long specified = 0L ;
        while( true )
        {
            long m = (l + u) / 2L ;

            if( ( m - sumDigits(m) ) >= s && ( (m-1) - sumDigits(m-1) ) < s  )
            {
                specified = m ;
                break ;
            }

            if( l > u  )
                break ;

            else
            {
                if( ( m - sumDigits(m) ) >= s )
                    u = m-1 ;
                else
                    l = m+1 ;
            }
        }

        out.println( n-specified+1 );
        out.flush();
        out.close();

    }

    public static int sumDigits(long n)
    {
        char [] a = (n+"").toCharArray();
        int sum = 0 ;
        for(int k = 0 ; k < a.length ; k++)
        {
            sum += Integer.parseInt(a[k]+"") ;
        }
        return sum ;
    }

}


import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;

public class Edu23 {

	public static int sum(String s){
		int tot=0;
		for(int i =0; i<s.length();i++){
			tot+=(s.charAt(i)-'0');
		}
		return tot;
	}
	public static BigInteger comb(int n, int k){
		if(k==0)
			return new BigInteger("1");
		else
			return comb(n,k-1).multiply(new BigInteger(n-k+1+"")).divide(new BigInteger(k+""));
	}
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long s = sc.nextLong();
		long i;
		for(i =s ; i-sum(i+"")<s;i++)
			if(i%10==0)i+=9;
		System.out.println(Math.max(0, n-i+1));

	}
	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

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

		public Scanner(String f) throws FileNotFoundException {
			br = new BufferedReader(new FileReader(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 {
			return Double.parseDouble(next());
		}

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

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

		public int[] nextIntArray1(int n) throws IOException {
			int[] a = new int[n + 1];
			for (int i = 1; i <= n; i++)
				a[i] = nextInt();
			return a;
		}

		public int[] shuffle(int[] a, int n) {
			int[] b = new int[n];
			for (int i = 0; i < n; i++)
				b[i] = a[i];
			Random r = new Random();
			for (int i = 0; i < n; i++) {
				int j = i + r.nextInt(n - i);
				int t = b[i];
				b[i] = b[j];
				b[j] = t;
			}
			return b;
		}

		public int[] nextIntArraySorted(int n) throws IOException {
			int[] a = nextIntArray(n);
			a = shuffle(a, n);
			Arrays.sort(a);
			return a;
		}

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

		public long[] nextLongArray1(int n) throws IOException {
			long[] a = new long[n + 1];
			for (int i = 1; i <= n; i++)
				a[i] = nextLong();
			return a;
		}

		public long[] nextLongArraySorted(int n) throws IOException {
			long[] a = nextLongArray(n);
			Random r = new Random();
			for (int i = 0; i < n; i++) {
				int j = i + r.nextInt(n - i);
				long t = a[i];
				a[i] = a[j];
				a[j] = t;
			}
			Arrays.sort(a);
			return a;
		}
	}
}


import java.util.Scanner;

/**
 *
 * 作者：张宇翔 创建日期：2017年6月16日 上午9:00:48 描述：写字楼里写字间，写字间里程序员； 程序人员写程序，又拿程序换酒钱。
 * 酒醒只在网上坐，酒醉还来网下眠； 酒醉酒醒日复日，网上网下年复年。 但愿老死电脑间，不愿鞠躬老板前； 奔驰宝马贵者趣，公交自行程序员。
 * 别人笑我忒疯癫，我笑自己命太贱； 不见满街漂亮妹，哪个归得程序员？
 */

public class Main {

	private final static int Max = (int) (1e5 + 10);
	private static long n,s;

	public static void main(String[] args) {
		InitData();
		GetAns();
	}

	private static void InitData() {
		Scanner cin = new Scanner(System.in);
		n=cin.nextLong();
		s=cin.nextLong();
	};
	private static void GetAns() {
		long i;
		long ans=0;
		for(i=s;i<=n;i++){

			long k=i-sum(i);
			if(k>=s){
				if(i%10==9){
					break;
				}
				ans++;
			}
		}
		if(n>=s){
			System.out.println(ans-i+n+1);
		}else{
			System.out.println(0);
		}
	};
	private static long sum(long ans){
		long sum=0;
		while(ans>0){
			sum+=(ans%10);
			ans/=10;
		}
		return sum;
	}
}


import java.util.Scanner;

public class C {

	public static void main(String[] args) {
		new C();
	}

	C() {

		Scanner in = new Scanner(System.in);

		long n = in.nextLong(), s = in.nextLong();
		long lo = 1, hi = 1000000000000000000L;

		while(lo<hi){
			//System.out.println(lo+" "+hi);
			//STUPID STUPID DUMB
			long mid = (lo+hi)/2;
			if(reallyBig(mid,s))
				hi = mid;
			else
				lo = mid+1;
		}

		//System.out.println(lo+" "+hi);
		if(!reallyBig(lo,s))
			System.out.println(0);
		else
			System.out.println(Math.max(n-lo+1,0));

		//System.out.println(reallyBig(100000000000000009L,100000000000000000L));

		in.close();

	}

	boolean reallyBig(long n, long s){
		int sum = 0;
		long temp = n;
		while(temp>0){
			sum += temp%10;
			temp/=10;
		}
		return n-sum>=s;
	}

}

/*

12 1

25 20

10 9

1000000000000000000 1000000000000000000

1000000000000000000 100000000000000000

 */