import java.math.BigInteger;
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner (System.in);
    public static void main(String[] args) {
    	int n = sc.nextInt();
    	int k = sc.nextInt();
    	char str[][] = new char[5][n];
        for(int i = 0;i < 4;i ++){
        	for(int j = 0;j < n;j ++)
                str[i][j] = '.';
        }
        if(k % 2 == 0){
            k /= 2;
            for(int i = 1;i <= 2;i++){
                for(int j = 1;j <= k;j++)
                     str[i][j] = '#';
            }
        }
        else{
            str[1][n / 2] = '#';
            if(k != 1){
                int tmp = n / 2;
                if(k <= n - 2){
                    for(int i = 1;i<= (k - 1) / 2;i++){
                        str[1][i] = '#';
                        str[1][n - 1 - i] = '#';
                    }
                }
                else{
                    for(int i = 1;i <= n - 2;i++) str[1][i] = '#';
                    k -= n - 2;
                    for(int i = 1;i <= k/2;i++){
                        str[2][i] = '#';
                        str[2][n - 1 - i]='#';
                    }
                }

            }
        }
        System.out.println("YES");
        for(int i = 0;i < 4;i ++){
        	System.out.println(str[i]);
        }
    }
 }


import java.util.Scanner;

public class HammingDistancesSum {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String  a = sc.nextLine(), b = sc.nextLine();
		long sum = 0;
		int frequency[][] = new int[200010][2];
		for (int i = 1; i <= b.length(); i++) {
	        for (int j = 0; j < 2; j++)
	            frequency[i][j] = frequency[i - 1][j];
	        frequency[i][Character.getNumericValue((b.charAt(i - 1)))]++;
	    }

	    for (int i = 0; i < a.length(); i++) {
	        int c = Character.getNumericValue(a.charAt(i));
	        for (int j = 0; j < 2; j++) {
	        	int flippingTerm = Math.abs(c - j);
	        	int endOfWindowValue = frequency[b.length() - a.length() + i + 1][j];
	        	int startOfWindowOffset = frequency[i][j];
	            sum += flippingTerm * (endOfWindowValue - startOfWindowOffset);
	        }
	    }
		System.out.println(sum);
		sc.close();
	}
}


import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Solution {
	public static void main(String[] args) {
		Solution solution = new Solution();
		System.out.println(solution.solve());
	}

	private int solve() {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int m = in.nextInt();

		int[] a = new int[m];
		for (int i = 0; i < m; ++i) a[i] = in.nextInt();

		if (n > m) return 0;

		Map<Integer, Integer> map = new HashMap<>();
		for (int k: a) map.put(k, map.getOrDefault(k, 0) + 1);

		List<Integer> keySet = new ArrayList<>(map.keySet());
		int end = m / n;

		keySet.sort((u, v) -> -Integer.compare(u, v));
		do {
			int count = 0;
			for (int k: keySet) {
				count += map.get(k) / end;
				if (count >= n) return end;
			}
		} while (--end > 0);

		return 0;
	}
}


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.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.StringTokenizer;

public class B {
	static ArrayList<Integer> [] adj;
	static int [] num;
	static int dfs(int u, int p){
		int cnt = 0;
		for(int v:adj[u]){
			if(v != p)
				cnt += dfs(v, u);
		}
		if(adj[u].size() == 1 && u != 0 || u == 0 && adj[0].size() == 0)
			cnt++;
		num[cnt]++;
		return cnt;
	}
	public static void main(String[] args) throws NumberFormatException, IOException {
		Scanner sc = new Scanner();
		PrintWriter out = new PrintWriter(System.out);
		int n = sc.nextInt();
		adj = new ArrayList[n];
		for (int i = 0; i < adj.length; ++i) {
			adj[i] = new ArrayList<>();
		}
		for (int i = 1; i < n; ++i) {
			int p = sc.nextInt()-1;
			adj[p].add(i);
			adj[i].add(p);
		}
		num = new int[n+1];
		dfs(0, -1);
		for (int i = 1; i < num.length; ++i) {
			num[i] += num[i-1];
		}
		int cur = 1;
		for (int i = 0; i < num.length; ++i) {
			while(cur <= num[i]){
				out.print(i + " ");
				++cur;
			}
		}
		out.close();
	}

	static class Scanner {
		BufferedReader br;
		StringTokenizer st;

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

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

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

}


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

public class CoveredPointsCount {

	//UPSOLVE

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

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());

		int n = Integer.parseInt(st.nextToken());

		long[] myArray = new long[2 * n];

			for (int i = 0; i < n; i++)  {
	        	StringTokenizer st1 = new StringTokenizer(br.readLine());
	        	myArray[2 * i] = Long.parseLong(st1.nextToken()) * 2;
	        	myArray[2 * i + 1] = Long.parseLong(st1.nextToken()) * 2 + 1;
	        }

	        Arrays.sort(myArray);
	        long[] ans = new long[n + 1];
	        int cnt = 0;

	        for (int i = 0; i < 2 * n - 1; i++)   {
	            if (myArray[i] % 2 == 0) cnt++; else cnt--;
	            ans[cnt] += (myArray[i + 1] + 1) / 2 - (myArray[i] + 1) / 2;
	        }

	        StringBuilder answer = new StringBuilder();

	        for (int i = 1; i < n + 1; i++) {
	        	answer.append(ans[i]);
	        	answer.append(" ");
	        }

	        System.out.println(answer);

	}

}


import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] P = new int[n];
        int[] check=new int[n];
        for (int i = 1; i < n; i++) {

            P[i] = scanner.nextInt();
            P[i]--;
            check[P[i]]++;
        }
        int[] leaves = new int[n];

        for (int i=0;i<n;i++) {
            if(check[i]==0){
                leaves[P[i]]++;
            }
        }

        for (int i = 0; i < n; i++) {

            if (check[i]>0&&leaves[i]<3) {
                System.out.println("No");
                return;
            }
        }
        System.out.println("Yes");
    }
}


import java .util.*;
import java .io.*;
public class Main{
	public static void main(String[]YAHIA_MOSTAFA){
		Scanner sc =new Scanner(System.in);
		long n=sc.nextLong(),x=sc.nextLong(),y=sc.nextLong();
		long xb,xw,yb,yw;
		xw=x-1;yw=y-1;xb=n-x;yb=n-y;
		if (x==n&&y==n){
			System.out.println("Black");return;
		}
		long c1=0,c2=0;
		long f =Math.max(xb,yb);
		long h =Math.max(xw,yw);
		//System.out.println(h+" "+f+" "+(h-f));
		if (h<=f)
			System.out.println("White");
		else
			System.out.println("Black");
	}
}


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

public class Main {
	static final int MAXN= 1005;
	static final long MOD =1_000_000_007;
	static final boolean DEBUG= false;
	static int  n, m;
	static long stlr[][]= new long[MAXN][MAXN],bell[]= new long[MAXN],occ[];
	static PrintStream cerr=System.err;
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Readin();
		stlr[0][0]= bell[0] =1;
		for (int i=1; i<=m; i++)
			for (int j=1;j<=i;j++) {
				stlr[i][j]= (stlr[i-1][j-1]+stlr[i-1][j]*(long)j)%MOD;
				bell[i]= (bell[i]+stlr[i][j])%MOD;
			}
		if (DEBUG)
			for (int i=1; i<=m; i++) cerr.println("Bell["+i+"] ="+bell[i]);
		Arrays.sort(occ);
		if (DEBUG) {
			cerr.println("After Sorting");
			for (int i=0;i<m; i++) cerr.println(occ[i]+" ");}
		long ans=1;
		for (int i=0,j=0; i<m; i=j) {
			for (j=i+1; j<m && occ[i]==occ[j];j++);
			ans= (ans*bell[j-i])%MOD;
		}
		System.out.println(ans);
	}
	static void Readin() {
		Scanner  cin;
		if ( !DEBUG)cin= new Scanner(System.in);
		else {
			try {
				cin = new Scanner(new File("input.txt"));
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				if ( DEBUG)cerr.println("Not Fount input.txt");
				return ;
			}
		}
		m = cin.nextInt(); n=cin.nextInt();
		occ= new long[m];
		for (int i=0; i<n; i++) {
			String s= cin.next();
			for (int j=0;j <m; j++)
				occ[j]|=((long)(s.charAt(j)-'0'))<<i;
		}
		cin.close();
	}
}


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

1088_D. Ehab and another another xor problem


import java.util.*;

import java.lang.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.*;

public class Main {

    public static void main(String[] args) throws Exception{
        FastReader sc=new FastReader();
        OutputStream outputStream = System.out;
        PrintWriter out = new PrintWriter(outputStream);
        int n=sc.nextInt();
        HashMap<String,Integer> map=new HashMap<String,Integer>();
        for(int i=0;i<n;i++) {
            map.put(sc.next(), 1);
        }
        ArrayList<String> list=new ArrayList<String>();
        int count=0;
        if(!map.containsKey("purple")) {
            count++;
            list.add("Power");
        }
if(!map.containsKey("green")) {
    count++;
    list.add("Time");
        }

if(!map.containsKey("blue")) {
    count++;
    list.add("Space");
}

if(!map.containsKey("orange")) {
    count++;
    list.add("Soul");
}

if(!map.containsKey("red")) {
    count++;
    list.add("Reality");
}

if(!map.containsKey("yellow")) {
    count++;
    list.add("Mind");
}System.out.println(count);
    for(String s:list) {
        System.out.println(s);
    }
    }
}

class FastReader
{
    BufferedReader br;
    StringTokenizer st;

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

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

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

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

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

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


import java.util.Scanner;

public class AlexAndARhombus {
	public static void main(String args[])
	{
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		System.out.println(n*n+(n-1)*(n-1));
		sc.close();
	}

}


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

public class Main
{
    static final long mod=(int)1e9+7;
    public static void main(String[] args) throws Exception
    {
    	FastReader in=new FastReader();
    	PrintWriter pw=new PrintWriter(System.out);
    	int n=in.nextInt();
    	long ans=0;
    	for(int i=2;2*i<=n;i++)
    	{
    		ans+=i*(n/i-1);
    	}
    	ans*=4;
    	pw.print(ans);
    	pw.flush();
    }
}

class pair
{
	int f,s;
}

class FastReader
{
    BufferedReader br;
    StringTokenizer st;

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

    public String next() throws IOException
    {
        if(st==null || !st.hasMoreElements())
        {
            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());
    }
}


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

public class A {
    public static void main(String args[]) {
        FastScanner scn = new FastScanner();
        int n = scn.nextInt();
        int s = scn.nextInt();
        if (s <= n) {
            System.out.println(1);
        } else if (s > n) {
            if(s%n == 0){
                System.out.println(s/n);
            } else {
                System.out.println(s/n + 1);
            }
        }

    }

    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

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


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

public class e {

public static class FastReader {
	BufferedReader br;
	StringTokenizer st;
	//it reads the data about the specified point and divide the data about it ,it is quite fast
	//than using direct

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

	String next() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (Exception r) {
				r.printStackTrace();
			}
		}
		return st.nextToken();
	}

	int nextInt() {
		return Integer.parseInt(next());//converts string to integer
	}

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

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

	String nextLine() {
		String str = "";
		try {
			str = br.readLine();
		} catch (Exception r) {
			r.printStackTrace();
		}
		return str;
	}
}
static ArrayList<String>list1=new ArrayList<String>();
static void combine(String instr, StringBuffer outstr, int index,int k)
{
	if(outstr.length()==k)
	{
		list1.add(outstr.toString());return;
	}
	if(outstr.toString().length()==0)
	outstr.append(instr.charAt(index));
    for (int i = 0; i < instr.length(); i++)
    {
        outstr.append(instr.charAt(i));

        combine(instr, outstr, i + 1,k);
        outstr.deleteCharAt(outstr.length() - 1);
    }
   index++;
}
static ArrayList<ArrayList<Integer>>l=new ArrayList<>();
static void comb(int n,int k,int ind,ArrayList<Integer>list)
{
	if(k==0)
	{
		l.add(new ArrayList<>(list));

		return;
	}

	for(int i=ind;i<=n;i++)
	{
		list.add(i);
		comb(n,k-1,ind+1,list);

		list.remove(list.size()-1);

	}

}

public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));

	public static void main(String[] args) {
		// TODO Auto-generated method stub

	FastReader in=new FastReader();
	HashMap<Integer,Integer>map=new HashMap<Integer,Integer>();

	int n=in.nextInt();
	int r=in.nextInt();

	double theta=(double)360/(double)n;

	double b=1-((double)2/(double)(1-Math.cos((double)2*Math.PI/(double)n)));
	double x=Math.sqrt(1-b)-1;
	double ans=(double)r/(double)x;
	System.out.println(ans);

	}
}


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

public class A {
    static MyScanner sc;
    static PrintWriter pw;

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

        n = sc.nextInt();
        T = sc.nextLong();
        p = new int[n];
        l = new int[n];
        x = new int[n];
        t = new int[n];
        adj = new ArrayList[n];

        for (int i = 0; i < n; i++)
            x[i] = sc.nextInt();
        for (int i = 0; i < n; i++)
            t[i] = sc.nextInt();
        adj[0] = new ArrayList<>();
        for (int i = 1; i < n; i++) {
            adj[i] = new ArrayList<>();
            p[i] = sc.nextInt() - 1;
            l[i] = sc.nextInt();
            adj[p[i]].add(i);
        }

        ftCnt = new long[N];
        ftSum = new long[N];
        ans = new long[n];

        dfs(0);
        pw.println(ans[0]);

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

    static int n;
    static long T;
    static int[] p, l, x, t;
    static ArrayList<Integer>[] adj;

    static long[] ans;

    static void dfs(int u) {
        update(t[u], x[u], 1L * x[u] * t[u]);
        ans[u] = getMaxCnt();
        long[] vals = {-1, -1, -1};
        for (int v : adj[u]) {
            T -= 2 * l[v];
            dfs(v);
            vals[0] = ans[v];
            Arrays.sort(vals);
            T += 2 * l[v];
        }
        if (u != 0) {
            if (vals[1] != -1)
                ans[u] = Math.max(ans[u], vals[1]);
        } else {
            if (vals[2] != -1)
                ans[u] = Math.max(ans[u], vals[2]);
        }
        update(t[u], -x[u], -1L * x[u] * t[u]);
    }

    static int N = (int) 1e6 + 2;
    static long[] ftCnt, ftSum;

    static void update(int idx, long cnt, long val) {
        while (idx < N) {
            ftCnt[idx] += cnt;
            ftSum[idx] += val;
            idx += (idx & -idx);
        }
    }

    static long getSum(int idx) {
        long ret = 0;
        while (idx > 0) {
            ret += ftSum[idx];
            idx -= (idx & -idx);
        }
        return ret;
    }

    static long getCnt(int idx) {
        long ret = 0;
        while (idx > 0) {
            ret += ftCnt[idx];
            idx -= (idx & -idx);
        }
        return ret;
    }

    static long getMaxCnt() {
        int start = 1, end = N - 1, ans = N - 1;
        while (start <= end) {
            int mid = (start + end) / 2;
            if (getSum(mid) >= T) {
                ans = mid;
                end = mid - 1;
            } else
                start = mid + 1;
        }
        long remT = T - (ans > 1 ? getSum(ans - 1) : 0);
        long cnt = (ans > 1 ? getCnt(ans - 1) : 0);
        long cntOfVal = getCnt(ans) - cnt;
        cnt += Math.min(cntOfVal, remT / ans);
        return cnt;
    }

    static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

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


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Code {

	public static void main(String[] args) throws IOException{
		 BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		 int n = Integer.parseInt(br.readLine());
		 HashMap<Double,Integer>h = new HashMap<>();
		 double [] temp = new double[n];
		 int m = 0;
		 for(int i=0;i<n;i++) {
			 String l = br.readLine();
			 int[] x = new int[4];
			 int k=0;
			 boolean t = false;
			 for(int j=0;j<l.length();j++) {
				 if(l.charAt(j)=='(' || l.charAt(j)=='+' || l.charAt(j)==')' || l.charAt(j)=='/')
					 x[k++] = j;
			 }
			 double a = Integer.parseInt(l.substring(x[0]+1,x[1]));
			 double b = Integer.parseInt(l.substring(x[1]+1, x[2]));
			 double c = Integer.parseInt(l.substring(x[3]+1));
			 temp[m++] = (a+b)/c;
			 //System.out.print((a+b)/c + " ");
			if(h.containsKey((a+b)/c))
					h.put((a+b)/c, h.get((a+b)/c)+1);
			else
				h.put((a+b)/c, 1);
		 }
		 //System.out.println(h);
		 for(int i=0;i<n;i++) {
			 System.out.print(h.get(temp[i]) + " ");
		 }
	}
	}


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

public class programA {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		if(n%2 == 0)System.out.println(n/2 +1);
		else System.out.println((int)Math.ceil((double)n/2));
	}
}


import java.math.BigInteger;
import java.util.Scanner;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Andy Phan
 */
public class p1096f {
    static long MOD = 998244353;
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        BIT invert = new BIT(n+5);
        BIT neg = new BIT(n+5);
        long res = 0;
        int[] arr = new int[n];
        boolean[] has = new boolean[n+1];
        long num1 = 0;
        for(int i = 0; i < n; i++) {
            arr[i] = in.nextInt();
            if(arr[i] != -1) {
                res += invert.read(n+5)-invert.read(arr[i]);
                res %= MOD;
                invert.update(arr[i], 1);
                has[arr[i]] = true;
            } else num1++;
        }
        if(num1 == 0) {
            System.out.println(res);
            return;
        }
        for(int i = 1; i <= n; i++) if(!has[i]) neg.update(i, 1);
        long invertNum1 = modInv(num1, MOD);
        res += ((num1*(num1-1))%MOD)*modInv(4, MOD);
        res %= MOD;
        long cnt = 0;
        for(int i = 0; i < n; i++) {
            if(arr[i] == -1) {
                cnt++;
                continue;
            }
            res += (((neg.read(n+5)-neg.read(arr[i]))*cnt)%MOD)*invertNum1;
            res %= MOD;
        }
        cnt = 0;
        for(int i = n-1; i >= 0; i--) {
            if(arr[i] == -1) {
                cnt++;
                continue;
            }
            res += (((neg.read(arr[i]))*cnt)%MOD)*invertNum1;
            res %= MOD;
        }
        System.out.println(res);
    }

    //@
    static class BIT {
            int n;
            int[] tree;
            public BIT(int n) {
                    this.n = n;
                    tree = new int[n + 1];
            }

            int read(int i) {
                    int sum = 0;
                    while (i > 0) {
                            sum += tree[i];
                            i -= i & -i;
                    }
                    return sum;
            }

            void update(int i, int val) {
                    while (i <= n) {
                            tree[i] += val;
                            i += i & -i;
                    }
            }
            //$
    }

    //@
    // Computes the modular inverse of x
    // Returns 0 if the GCD of x and mod is not 1
    // O(log n)  :  Can be converted to use BigIntegers
    static long modInv(long x, long mod) {
        return (BigInteger.valueOf(x).modInverse(BigInteger.valueOf(mod))).longValue();
    }

    static long modInv(long a, long b, long y0, long y1, long q0, long q1) {
            long y2 = y0 - y1*q0;
            return b == 0 ? y2 : modInv(b, a % b, y1, y2, q1, a / b);
    }

    //@
    static long gcd(long a, long b) { return b == 0 ? a : gcd(b, a % b); }
    static long lcm(long a, long b) { return a / gcd(a, b) * b; }

}


import java.util.*;
import java.io.*;
public class Waw{

    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] a = new long[n];
        for(int i=0;i<n;i++) a[i] = sc.nextLong();
        long[] p = new long[n];
        p[n-1] = a[n-1];
        for(int i=n-2;i>=0;i--){
            if(a[i]<p[i+1]) p[i] = p[i+1]-1;
            else p[i] = a[i];
        }
        long max = p[0];
        long res = p[0] - a[0];
        for(int i=1;i<n;i++){
            if(max < p[i]) max = p[i];
            res += max - a[i];
        }
        System.out.println(res);
    }
}


import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.StringTokenizer;
import java.io.InputStream ;
import java.util.InputMismatchException;
import java.util.ArrayList;

public class Main {
    public static void main(String[] args) throws IOException {
        PrintWriter out = new PrintWriter(System.out);
        //Scanner sc = new Scanner();
        Reader in = new Reader();
        Main solver = new Main();
        solver.solve(out, in);
        out.flush();
        out.close();

    }

    void solve(PrintWriter out, Reader in) throws IOException{
        int n = in.nextInt();
        int m = in.nextInt();

        int[] vert = new int[n+1];
        for(int i=0 ;i<n ;i++) vert[i] = in.nextInt();
        vert[n] = (int)1e9;

        int cnt=0,x,y;
        ArrayList<Integer> arr = new ArrayList<>();
        for(int i=0 ;i<m ;i++) {
            x = in.nextInt();
            y = in.nextInt();
            in.nextInt();

            if(x==1) arr.add(y);
        }

        horz = new int[arr.size()];
        for(int i=0 ;i<arr.size();i++) horz[i] = arr.get(i);

        Arrays.sort(horz);
        Arrays.sort(vert);

        int ans = 2*(int)1e5+10;
        for(int i=0 ;i<=n ;i++){
            int lesshorz = bs(vert[i],horz.length);
            ans = Math.min(ans,i+horz.length-lesshorz-1);
        }
        out.println(ans);
    }

    static int[] horz;

    static int bs(int num,int m){
        int mid,lo=0,hi=m-1,r=-1;

        while(lo<=hi){
            mid = (lo+hi)/2;
            if(horz[mid]<num){
                lo = mid+1;
                r = mid;
            }else{
                hi =mid-1;
            }
        }
        return r;
    }

    static class Reader {

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

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

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

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

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

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

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

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

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

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

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

    }
}


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

public class D {

    private void solve() {
        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);

        int n = nextInt(), m = nextInt();
        boolean[][] used = new boolean[n + 1][m + 1];

        for (int j = 1; j <= (m + 1) / 2; j++) {
            int x1 = 1, x2 = n;
            for (int i = 1; i <= n; i++) {
                if (x1 <= n && !used[x1][j]) {
                    out.println(x1 + " " + j);
                    used[x1++][j] = true;
                }
                if (x2 > 0 && !used[x2][m - j + 1]) {
                    out.println(x2 + " " + (m - j + 1));
                    used[x2--][m - j + 1] = true;
                }
            }
        }

        out.close();
    }

    public static void main(String[] args) {
        new D().solve();
    }

    private BufferedReader br;
    private StringTokenizer st;
    private PrintWriter out;

    private String next() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
        return st.nextToken();
    }

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

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

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


/* package whatever; // don't place package name! */

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

/* Name of the class has to be "Main" only if the class is public. */
public class Ideone
{
	static int check(int temp)
	{
		int count1 = 0;
    while (temp>0)
    {
        if(temp % 2 != 0)
        count1++;
        temp/= 2;
    }
    return count1;
	}
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		Scanner sc=new Scanner(System.in);
		String a=sc.next();
		String b=sc.next();
		int m=a.length();
		int n=b.length();
		int[] zero=new int[n];
		int[] one=new int[n];

		for(int i=0;i<n;i++)
		{
			if(i==0)
			{
				if(b.charAt(i)=='0')
				zero[i]++;
				else
				one[i]++;
			}
			else
			{
				zero[i]=zero[i-1];
				one[i]=one[i-1];
				if(b.charAt(i)=='0')
				zero[i]++;
				else
				one[i]++;
		    }
		}

		long res=0;
		for(int i=0;i<m;i++)
		{
		int x=n-m+i;
		if(a.charAt(i)=='0')
		res+=one[x];
		else
		res+=zero[x];
		if(i>0)
		{
			if(a.charAt(i)=='0')
			res-=one[i-1];
			else
			res-=zero[i-1];
		}
		}

		System.out.println(res);
	}
}


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

public class _1036_B_DiagonalWalkingV2 {

	public static void main(String[] args) throws IOException {
		int Q = readInt();
		while(Q-- > 0) {
			long n = readLong(), m = readLong(), k = readLong();
			if(Math.max(n, m) > k) println(-1);
			else {
				long ans = k;
				if(n%2 != k%2) ans--;
				if(m%2 != k%2) ans--;
				println(ans);
			}
		}
		exit();
	}

	final private static int BUFFER_SIZE = 1 << 16;
	private static DataInputStream din = new DataInputStream(System.in);
	private static byte[] buffer = new byte[BUFFER_SIZE];
	private static int bufferPointer = 0, bytesRead = 0;
	static PrintWriter pr = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

	public static String readLine() throws IOException {
		byte[] buf = new byte[64]; // line length
		int cnt = 0, c;
		while ((c = Read()) != -1) {
			if (c == '\n')
				break;
			buf[cnt++] = (byte) c;
		}
		return new String(buf, 0, cnt);
	}

	public static String read() throws IOException {
		byte[] ret = new byte[1024];
		int idx = 0;
		byte c = Read();
		while (c <= ' ') {
			c = Read();
		}
		do {
			ret[idx++] = c;
			c = Read();
		} while (c != -1 && c != ' ' && c != '\n' && c != '\r');
		return new String(ret, 0, idx);
	}

	public static int readInt() throws IOException {
		int ret = 0;
		byte c = Read();
		while (c <= ' ')
			c = Read();
		boolean neg = (c == '-');
		if (neg)
			c = Read();
		do {
			ret = ret * 10 + c - '0';
		} while ((c = Read()) >= '0' && c <= '9');

		if (neg)
			return -ret;
		return ret;
	}

	public static long readLong() throws IOException {
		long ret = 0;
		byte c = Read();
		while (c <= ' ')
			c = Read();
		boolean neg = (c == '-');
		if (neg)
			c = Read();
		do {
			ret = ret * 10 + c - '0';
		} while ((c = Read()) >= '0' && c <= '9');
		if (neg)
			return -ret;
		return ret;
	}

	public static double readDouble() throws IOException {
		double ret = 0, div = 1;
		byte c = Read();
		while (c <= ' ')
			c = Read();
		boolean neg = (c == '-');
		if (neg)
			c = Read();

		do {
			ret = ret * 10 + c - '0';
		} while ((c = Read()) >= '0' && c <= '9');

		if (c == '.') {
			while ((c = Read()) >= '0' && c <= '9') {
				ret += (c - '0') / (div *= 10);
			}
		}

		if (neg)
			return -ret;
		return ret;
	}

	private static void fillBuffer() throws IOException {
		bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
		if (bytesRead == -1)
			buffer[0] = -1;
	}

	private static byte Read() throws IOException {
		if (bufferPointer == bytesRead)
			fillBuffer();
		return buffer[bufferPointer++];
	}

	static void print(Object o) {
		pr.print(o);
	}

	static void println(Object o) {
		pr.println(o);
	}

	static void flush() {
		pr.flush();
	}

	static void println() {
		pr.println();
	}

	static void exit() throws IOException {
		din.close();
		pr.close();
		System.exit(0);
	}
}


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.PrintWriter;

import java.util.*;
import java.util.Arrays ;
import java .lang.String.* ;
import java .lang.StringBuilder ;

public class Test{
    static int pos = 0 ;
    static int  arr[] ;
  static LinkedList l1 = new  LinkedList() ;
static void find(int p ,char[]x,int put[],String s){
    int c= 0 ;
    for (int i = 0; i < s.length(); i++) {
        if(x[p]==s.charAt(i)){
        c++ ; }
    }
    put[p] = c ;
}
static int mode(int m ,int[]x ){
    int temp = 0 ;
    for (int i = x.length-1; i >=0; i--) {
        if(x[i]<=m){
            temp= x[i] ;
           /// break ;
             return m-temp ;

        }
    }
     return m-temp ;
}
static int mode2(int m ,int[]x ){
    int temp = 0 ;

    for (int i = x.length-1; i >=0; i--) {
        if(x[i]<=m){
            temp= x[i] ;
           /// break ;
             return x[i] ;

        }
    }
     return 0 ;
}
static int find(int x[],int temp){
    int j = 0 ;
    for (int i = x.length-1; i >=0; i--) {
        if(x[i]==temp) return j+1 ;
        j++ ;
    }
    return -1 ;
}
static String ch(long[]x,long b){
    for (int i = 0; i < x.length; i++) {
        if(x[i]==b)return "YES" ;
    }
    return "NO" ;
}

    public static void main(String[] args)  {

        Scanner in = new Scanner(System.in) ;
        PrintWriter pw = new PrintWriter(System.out);
        long n = in.nextLong() ;
        long count =1 ;
        long temp =n/2;
     temp+=count ;

        System.out.println(temp);
 }
}


import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner in=new Scanner(System.in);
		String str=in.next();
		int cnt=0;
		for(int i=0;i<str.length();++i) {
			if(str.charAt(i)=='1') {
				++cnt;
			}
		}
		int i=0;
		for(;i<str.length();++i) {
			if(str.charAt(i)=='0') {
				System.out.print("0");
			}
			else if(str.charAt(i)=='2') {
				while(cnt-->0) {//
					System.out.print("1");
				}
				System.out.print("2");
			}
		}
		while(cnt-->0) {
			System.out.print("1");
		}
		in.close();
	}
}


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

public class FunctionHeight {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        long n = sc.nl();
        long k = sc.nl();
        long ans = (n+k-1)/n;
        System.out.println(ans);
    }

    /////////// TEMPLATE FROM HERE /////////////////
    private static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

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

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

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

        float nf() {
            return Float.parseFloat(next());
        }

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

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

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


import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Scanner;

public class A1 {

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

        long size = scan.nextLong();
        int numberOfSpecial = scan.nextInt();
        long pageSize = scan.nextLong();

        long[] specialItemsArray = new long[numberOfSpecial];
        for (int i = 0; i < numberOfSpecial; i++) {
            specialItemsArray[i] = scan.nextLong();
        }

        int totalRemoved = 0;
        int step = 0;

        long currentPageIndex = BigDecimal.valueOf(specialItemsArray[0]).divide(BigDecimal.valueOf(pageSize),2, RoundingMode.UP).setScale(0, RoundingMode.CEILING).longValue();
        int specialItemArrayIndex = 1;

        while (specialItemArrayIndex < numberOfSpecial) {
            long pageIndex = BigDecimal.valueOf(specialItemsArray[specialItemArrayIndex] - totalRemoved).divide(BigDecimal.valueOf(pageSize),2,RoundingMode.UP).setScale(0, RoundingMode.CEILING).longValue();
            if (currentPageIndex != pageIndex) {
                step++;
                totalRemoved = specialItemArrayIndex;
                currentPageIndex =  BigDecimal.valueOf(specialItemsArray[specialItemArrayIndex] - totalRemoved).divide(BigDecimal.valueOf(pageSize),2,RoundingMode.UP).setScale(0, RoundingMode.CEILING).longValue();
            }
            specialItemArrayIndex++;
        }

        System.out.println(step + 1);

    }

}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.TreeMap;

public class Main {

	static class Task {

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

		public void solve(InputReader in, PrintWriter out) {
			int t = in.nextInt();
			while(t-->0) {
				long n =in.nextLong();
				long m = in.nextLong();
				long x1 = in.nextLong();
				long y1 = in.nextLong();
				long x2 = in.nextLong();
				long y2 = in.nextLong();
				long x3 = in.nextLong();
				long y3 = in.nextLong();
				long x4 = in.nextLong();
				long y4 = in.nextLong();
				long w = white(1, 1, m, n);
				long b = black(1, 1, m, n);
				long whited = 0;
				if(x3 > x2 || x4 < x1 || y3 > y2 || y4 < y1) {
					whited = black(x1, y1, x2, y2);
				} else {
					whited = black(x1, y1, x2, y2);
					long xm1 = Math.max(x1, x3);
					long ym1 = Math.max(y1, y3);
					long xm2 = Math.min(x2, x4);
					long ym2 = Math.min(y2, y4);
					whited -= black(xm1, ym1, xm2, ym2);
				}
				b -= whited;w += whited;
				long blacked = white(x3, y3, x4, y4);
				w-= blacked;b += blacked;
				out.println(w + " " + b);
			}
		}

		long black(long x1, long y1, long x2, long y2) {
			long dx = (x2 - x1) + 1;
			long dy = (y2 - y1) + 1;
			if((x1+y1)%2!=0) {
				return ((dy+1)/2)*((dx+1)/2)+(dy/2)*(dx/2);
			}
			return ((dy+1)/2)*((dx)/2)+(dy/2)*((dx+1)/2);
		}

		long white(long x1, long y1, long x2, long y2) {
			long dx = (x2 - x1) + 1;
			long dy = (y2 - y1) + 1;
			if((x1+y1)%2==0) {
				return ((dy+1)/2)*((dx+1)/2)+(dy/2)*(dx/2);
			}
			return ((dy+1)/2)*(dx/2)+(dy/2)*((dx+1)/2);
		}

	}

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

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

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

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

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

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

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

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

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

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

    }

}


/**
 * Created by Baelish on 8/28/2018.
 */

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

public class F_DSU {
    public static void main(String[] args)throws Exception {
        FastReader in = new FastReader(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        n = in.nextInt();

        int brr[] = new int[2*n];
        for (int i = 0; i < 2*n; i+= 2) {
            brr[i] = in.nextInt();
            brr[i+1] = in.nextInt();
        }

        arr = shrink(brr);
        int imap[] = new int[2*n];
        for (int i = 0; i < 2*n; i++) {
            imap[arr[i]] = brr[i];
        }

        int idx = binarySearch(arr.length);
        if(idx >= arr.length) pw.println(-1);
        else pw.println(imap[idx]);

        pw.close();
    }
    static int n, arr[];

    static int binarySearch(int H) {
        int lo = 0, hi = H, mid;
        while (lo < hi) {
            mid = (lo + hi) / 2;
            if (check(mid)) hi = mid;
            else lo = mid + 1;
        }
        if(lo > 0 && check(lo-1)) return lo-1;
        return lo;
    }

    static boolean check(int m){
        DSU dsu = new DSU(2*n);
        for (int i = 0; i < n; i++) {
            int u = arr[2*i], v = arr[2*i+1];
            if(u > m) return false;
            if(v > m){
                if(++dsu.cycle[dsu.find(u)] >= 2) return false;
            }
            else{
                if(!dsu.union(u, v)){
                    if(++dsu.cycle[dsu.find(u)] >= 2) return false;
                }
                else{
                    if(dsu.cycle[dsu.find(u)] >= 2) return false;
                }
            }
        }
        return true;
    }

    static class DSU{
        int parent[], cycle[], n;
        DSU(int N){
            n = N;
            parent = new int[N];
            cycle = new int[N];
            for(int i = 0; i < N; i++){
                parent[i] = i;
            }
        }

        DSU(int [] p){
            parent = p; n = p.length;
        }

        int find(int i) {
            int p = parent[i];
            if (i == p) return i;
            return parent[i] = find(p);
        }

        boolean equiv(int u, int v){
            return find(u) == find(v);
        }

        boolean union(int u, int v){
            u = find(u); v = find(v);
            if(u != v) {
                parent[u] = parent[v];
                cycle[v] += cycle[u];
            }
            return u != v;
        }

        int count(){
            int cnt = 0;
            for(int i = 0; i < n; i++){
                if(i == find(i)) cnt++;
            }
            return cnt;
        }
    }

    public static int[] shrink(int[] a) {
        int n = a.length;
        long[] b = new long[n];
        for(int i = 0;i < n;i++)b[i] = (long)a[i]<<32|i;
        Arrays.sort(b);
        int[] ret = new int[n];
        int p = 0;
        for(int i = 0;i < n;i++) {
            if(i>0 && (b[i]^b[i-1])>>32!=0)p++;
            ret[(int)b[i]] = p;
        }
        return ret;
    }

    static void debug(Object...obj) {
        System.err.println(Arrays.deepToString(obj));
    }

    static class FastReader {
        InputStream is;
        private byte[] inbuf = new byte[1024];
        private int lenbuf = 0, ptrbuf = 0;
        static final int ints[] = new int[128];

        public FastReader(InputStream is){
            for(int i='0';i<='9';i++) ints[i]=i-'0';
            this.is = is;
        }

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

        public boolean isSpaceChar(int c) {
            return !(c >= 33 && c <= 126);
        }
        public int skip() {
            int b;
            while((b = readByte()) != -1 && isSpaceChar(b));
            return b;
        }

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

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

            while(true){
                if(b >= '0' && b <= '9'){
                    num = (num<<3) + (num<<1) + ints[b];
                }else{
                    return minus ? -num : num;
                }
                b = readByte();
            }
        }

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

            while(true){
                if(b >= '0' && b <= '9'){
                    num = (num<<3) + (num<<1) + ints[b];
                }else{
                    return minus ? -num : num;
                }
                b = readByte();
            }
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }
       /* public char nextChar() {
            return (char)skip();
        }*/

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

        /*private char buff[] = new char[1005];
        public char[] nextCharArray(){
            int b = skip(), p = 0;
            while(!(isSpaceChar(b))){
                buff[p++] = (char)b;
                b = readByte();
            }
            return Arrays.copyOf(buff, p);
        }*/
    }
}


import java.io.*;

public class n5D
{
    public static void main(String[] args)
    {
        double a = 0, v = 0, l = 0, d = 0, w = 0;
        try
        {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            String[] str = br.readLine().split(" ");
            a = Double.parseDouble(str[0]);
            v = Double.parseDouble(str[1]);
            str = br.readLine().split(" ");
            l = Double.parseDouble(str[0]);
            d = Double.parseDouble(str[1]);
            w = Double.parseDouble(str[2]);
        }
        catch(Exception e)
        {
            System.out.println(e);
        }

        double t1, t2, t3, t4, t5, t, D = 0;

        if (w > v) w = v;
        t2 = d / v - v / a + w * w / 2 / a / v;
        if (t2 >= 0)
        {
            t1 = v / a;
            t3 = t1 - w / a;
        }
        else
        {
            if (Math.sqrt(2 * d / a) > (w / a))
            {
                t1 = Math.sqrt((2 * a * d + w * w) / (a * a * 2));
                t3 = t1 - w / a;
            }
            else
            {
                t1 = Math.sqrt(2 * d / a);
                t3 = 0;
            }
            t2 = 0;
        }
        t5 = (l - d - v * v / 2 / a + a * (t1 - t3) * (t1 - t3) / 2) / v;
        if (t5 >= 0) t4 = v / a - (t1 - t3);
        else
        {
            t5 = 0;
            t4 = -t1 + t3 + Math.sqrt((t1 - t3) * (t1 - t3) + 2 * (l - d) / a);
        }
        t = t1 + t2 + t3 + t4 + t5;
        System.out.println(t);
        //System.out.println(t1 + " " + t2 + " " + t3 + " " + t4 + " " + t5);
    }
}


import java.util.*;
import java.io.*;
public class Solution{

    public static long page(long p,long k){

        return (p-1)/k;

    }

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

        long n = sc.nextLong();
        int m = sc.nextInt();
        long k = sc.nextLong();
        long[] p = new long[m];
        long del = 0;
        long nb = 1;
        int op = 0;
        for(int i=0;i<m;i++) p[i] = sc.nextLong();
        for(int i=1;i<m;i++){
            if(page(p[i]-del,k)!=page(p[i-1]-del,k)){

                del += nb;
                nb = 1;
                op++;

            }else{
                nb++;

            }
        }
        if(nb!=0) op++;

        System.out.println(op);

    }

}


import java.io.PrintWriter;

import java.util.*;
import java.util.Arrays ;
import java .lang.String.* ;
import java .lang.StringBuilder ;

public class Test{
    static int pos = 0 ;
    static int  arr[] ;
  static LinkedList l1 = new  LinkedList() ;
static void find(int p ,char[]x,int put[],String s){
    int c= 0 ;
    for (int i = 0; i < s.length(); i++) {
        if(x[p]==s.charAt(i)){
        c++ ; }
    }
    put[p] = c ;
}
static int mode(int m ,int[]x ){
    int temp = 0 ;
    for (int i = x.length-1; i >=0; i--) {
        if(x[i]<=m){
            temp= x[i] ;
           /// break ;
             return m-temp ;

        }
    }
     return m-temp ;
}
static int mode2(int m ,int[]x ){
    int temp = 0 ;

    for (int i = x.length-1; i >=0; i--) {
        if(x[i]<=m){
            temp= x[i] ;
           /// break ;
             return x[i] ;

        }
    }
     return 0 ;
}
static int find(int x[],int temp){
    int j = 0 ;
    for (int i = x.length-1; i >=0; i--) {
        if(x[i]==temp) return j+1 ;
        j++ ;
    }
    return -1 ;
}
static String ch(long[]x,long b){
    for (int i = 0; i < x.length; i++) {
        if(x[i]==b)return "YES" ;
    }
    return "NO" ;
}

    public static void main(String[] args)  {

        Scanner in = new Scanner(System.in) ;
        PrintWriter pw = new PrintWriter(System.out);
     int k=in.nextInt(), n=in.nextInt(), s=in.nextInt(), p=in.nextInt() ;
     int paper =n/s;
     if(n%s!=0) paper++ ;
     paper*=k ;
     int fin = paper/p ;
     if(paper%p!=0) fin++ ;
        System.out.println( fin );

 }
}


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

public class SolutionB {
      public static void main(String args[])throws IOException{
              Scanner sc = new Scanner(System.in);
              int a[] = new int[1501];
              for(int i = 0; i < 3; i++){
                     a[sc.nextInt()]++;
              }
              if(a[1] > 0 || a[2] > 1 || a[3] > 2 || (a[4] == 2 && a[2] == 1)){
                     System.out.println("YES");
              }else{
                     System.out.println("NO");
              }
      }
}


import java.io.IOException;
import java.io.InputStream;
import java.util.InputMismatchException;
import java.util.Stack;
public class D527A2 {

	public static void main(String[] args) {
		FastScanner in = new FastScanner(System.in);
		int N = in.nextInt();
		Stack<Integer> stack = new Stack<>();
		for(int i = 0; i < N; i++) {
			int num = in.nextInt() % 2;
			if(stack.size() >= 1 && stack.lastElement() == num)
				stack.pop();
			else
				stack.add(num);
		}

		System.out.println(stack.size() <= 1 ? "YES" : "NO");
	}

	/**
	 * Source: Matt Fontaine
	 */
	static class FastScanner {
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int chars;

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

		int read() {
			if (chars == -1)
				throw new InputMismatchException();
			if (curChar >= chars) {
				curChar = 0;
				try {
					chars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (chars <= 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();
		}
	}

}
/*
5
2 1 1 2 5
outputCopy
YES
inputCopy
3
4 5 3
outputCopy
YES
inputCopy
2
10 10
outputCopy
YES
inputCopy
3
1 2 3
outputCopy
NO

5
2 3 2 2 3

YES
*/


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

public class stacks {

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

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

		long remove = 0;

		int[] heights = new int[n+1];

		for(int i = 0; i < n; i++) {
			heights[i] = sc.nextInt();
			remove += heights[i];
		}

		Arrays.sort(heights);
		//System.out.println(Arrays.toString(heights));
		long keep = 0;
		for(int i = n; i> 0; i--) {
			if(heights[i-1] >= heights[i]) {
				heights[i-1] = heights[i]-1;
			}
			keep += heights[i] - heights[i-1];
		}
		//System.out.println(Arrays.toString(heights));

		pw.println(remove - keep);
		pw.close();
	}

	static class FastIO {

		//Is your Fast I/O being bad?

		InputStream dis;
		byte[] buffer = new byte[1 << 17];
		int pointer = 0;

		public FastIO(String fileName) throws Exception {
			dis = new FileInputStream(fileName);
		}

		public FastIO(InputStream is) throws Exception {
			dis = is;
		}

		int nextInt() throws Exception {
			int ret = 0;

			byte b;
			do {
				b = nextByte();
			} while (b <= ' ');
			boolean negative = false;
			if (b == '-') {
				negative = true;
				b = nextByte();
			}
			while (b >= '0' && b <= '9') {
				ret = 10 * ret + b - '0';
				b = nextByte();
			}

			return (negative) ? -ret : ret;
		}

		long nextLong() throws Exception {
			long ret = 0;

			byte b;
			do {
				b = nextByte();
			} while (b <= ' ');
			boolean negative = false;
			if (b == '-') {
				negative = true;
				b = nextByte();
			}
			while (b >= '0' && b <= '9') {
				ret = 10 * ret + b - '0';
				b = nextByte();
			}

			return (negative) ? -ret : ret;
		}

		byte nextByte() throws Exception {
			if (pointer == buffer.length) {
				dis.read(buffer, 0, buffer.length);
				pointer = 0;
			}
			return buffer[pointer++];
		}

		String next() throws Exception {
			StringBuffer ret = new StringBuffer();

			byte b;
			do {
				b = nextByte();
			} while (b <= ' ');
			while (b > ' ') {
				ret.appendCodePoint(b);
				b = nextByte();
			}

			return ret.toString();
		}

	}
}


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

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

    static class TaskC {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();

            TaskC.pair[] songs = new TaskC.pair[n];
            long sum = 0;
            for (int i = 0; i < n; i++) {
                songs[i] = new TaskC.pair(in.nextInt(), in.nextInt());
                sum += songs[i].a;
            }
            Arrays.sort(songs);

            int res = 0;
            int idx = n - 1;
            while (sum > m) {
                if (idx < 0) {
                    break;
                }
                sum -= (songs[idx].a - songs[idx].b);

                res++;
                idx--;
            }

            if (sum > m) {
                out.println(-1);
            } else {
                out.println(res);
            }
        }

        static class pair implements Comparable<TaskC.pair> {
            int a;
            int b;

            pair(int a, int b) {
                this.a = a;
                this.b = b;
            }

            public int compareTo(TaskC.pair p) {
                return (this.a - this.b) - (p.a - p.b);
            }

        }

    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

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

        public Scanner(String s) {
            try {
                br = new BufferedReader(new FileReader(s));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

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

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

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
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 gaidash
 */
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);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            final int SIZE = 256;
            final int UNDEF = -1;

            int nPixels = in.nextInt();
            int groupSize = in.nextInt();
            int[] a = in.nextIntArray(nPixels);
            boolean[] exists = new boolean[SIZE];
            int[] left = new int[SIZE];
            int[] right = new int[SIZE];
            int[] ret = new int[nPixels];
            Arrays.fill(ret, UNDEF);

            for (int i = 0; i < nPixels; i++) {
                for (int p = 0; p < SIZE; p++) {
                    if (exists[p] && left[p] <= a[i] && a[i] <= right[p]) {
                        ret[i] = left[p];
                        left[a[i]] = left[p];
                        right[a[i]] = right[p];
                        break;
                    }
                }
                if (ret[i] == UNDEF) {
                    int l = Math.max(a[i] - groupSize + 1, 0);
                    int r = l + groupSize - 1;
                    for (int p = a[i] - 1; p >= 0; p--) {
                        if (exists[p]) {
                            if (p >= l) {
                                int d = p - l;
                                l = p + 1;
                                r += d + 1;
                            }
                            if (right[p] >= l) {
                                right[p] = l - 1;
                            }
                        }
                    }
                    for (int p = a[i] + 1; p < SIZE; p++) {
                        if (exists[p] && left[p] <= r) {
                            r = left[p] - 1;
                        }
                    }
                    left[a[i]] = l;
                    right[a[i]] = r;
                    ret[i] = l;
                }
                exists[a[i]] = true;
            }
//        for (int p : a) {
//            System.out.println("Segment for pixel " + p + " = " + "(" + left[p] + " , " + right[p] + ")");
//        }

            out.print(ret);
        }

    }

    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(int[] array) {
            for (int i = 0; i < array.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(array[i]);
            }
        }

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

    }

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

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

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

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

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

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

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

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

        }

    }
}


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

public class Main {

	static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            try {
                br = new BufferedReader(new InputStreamReader(System.in));
                st = new StringTokenizer(br.readLine());
            } catch (Exception e){e.printStackTrace();}
        }

        public String next() {
            if (st.hasMoreTokens()) return st.nextToken();
            try {st = new StringTokenizer(br.readLine());}
            catch (Exception e) {e.printStackTrace();}
            return st.nextToken();
        }

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

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

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

        public String nextLine() {
            String line = "";
            if(st.hasMoreTokens()) line = st.nextToken();
            else try {return br.readLine();}catch(IOException e){e.printStackTrace();}
            while(st.hasMoreTokens()) line += " "+st.nextToken();
            return line;
        }
    }
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter pw = new PrintWriter(System.out);

        int n = sc.nextInt();
        int best = 1;
        int bestTime = Integer.MAX_VALUE;
        for(int i=0;i<n;i++) {
            int time;
            int a = sc.nextInt();
            time = (a%n==0 || a%n<=i) ? a/n : (a+n)/n;
            if(time < bestTime) {
                best = i + 1;
                bestTime = time;
            }
        }

        pw.println(best);
        pw.close();
    }
}


//package codeforces;
import java.util.Scanner;
public class ex5 {
public static void main(String[] args) {
	Scanner scan = new Scanner(System.in);
	String S [] = new String[3];

	int m=0,s=0,p=0;
	int temp=0;

	for (int i = 0; i < S.length; i++) {
		S[i]=scan.next();
		if(S[i].indexOf('m')!=-1) m++;
		if(S[i].indexOf('s')!=-1) s++;
		if(S[i].indexOf('p')!=-1) p++;
	}

	int n1 = Integer.parseInt(S[0].substring(0,1));
	int n2 = Integer.parseInt(S[1].substring(0,1));
	int n3 = Integer.parseInt(S[2].substring(0,1));

	    int d3 = Math.abs(n1-n2);
		int d4 = Math.abs(n1-n3);
		int d5 = Math.abs(n2-n3);

	if(m==3||s==3||p==3) {

		    if(d3==1&d5==1&d4==2||d3==1&d4==1&d5==2||d5==1&d4==1&d3==2)
			System.out.println(0);
		else
		    if(d3==0&d4==0) System.out.println(0);
		else
			if(d3<d5&d3<d4) {
			    if(d3==1||d3==2||d3==0) System.out.println(1);
		        else                 System.out.println(2);
			    }
			else if (d5<d4&d5<d3){
				 if(d5==1||d5==2||d5==0) System.out.println(1);
					else                 System.out.println(2);
			}
			else if(d4<d5&d4<d3) {
				if(d4==1||d4==2||d4==0) System.out.println(1);
				else                 System.out.println(2);
			}
			else if(d3==2&d5==2||d4==2&d5==2||d3==2&d4==2||d3==1&d5==1||d4==1&d5==1||d3==2&d4==1)
				System.out.println(1);
			else System.out.println(2);

	}

	if(m==2||s==2||p==2) {

		char c1 = S[0].charAt(1);
		char c2 = S[1].charAt(1);
		char c3 = S[2].charAt(1);

		if(c1==c2) {
			if(n1==n2) System.out.println(1);
			else if(d3==1||d3==2) System.out.println(1);
			else System.out.println(2);
		}
		if(c1==c3) {
			if(n1==n3) System.out.println(1);
			else if(d4==1||d4==2) System.out.println(1);
			else System.out.println(2);
		}
		if(c2==c3) {
			if(n2==n3) System.out.println(1);
			else if(d5==1||d5==2) System.out.println(1);
			else System.out.println(2);
		}
	}

	if(m==1&s==1&p==1) System.out.println(2);

}
}


import java.util.*;

public class Main {
	static int mod = 1000000007;
  static int size = 200000;
	static long[] fac = new long[size];
	static long[] finv = new long[size];
	static long[] inv = new long[size];
	static int INF = Integer.MAX_VALUE;

 	public static void main(String[] args){
		Scanner scanner = new Scanner(System.in);
		String[] s = new String[2];
		for(int i = 0; i < 2; i++){
			s[i] = scanner.next();
		}
		int n = s[0].length();
		char[][] c = new char[2][n];
		for(int i = 0; i < 2; i++){
			for(int j = 0; j < n; j++){
				c[i][j] = s[i].charAt(j);
			}
		}
		int count = 0;
		for(int i = 0; i < n-1; i++){
			if(c[0][i] == '0' && c[1][i] == '0' && c[0][i+1] == '0'){
				c[0][i] = 'X';
				c[1][i] = 'X';
				c[0][i+1] = 'X';
				count++;
			}
			if(c[0][i] == '0' && c[1][i] == '0' && c[1][i+1] == '0'){
				c[0][i] = 'X';
				c[1][i] = 'X';
				c[1][i+1] = 'X';
				count++;
			}
			if(c[0][i] == '0' && c[0][i+1] == '0' && c[1][i+1] == '0'){
				c[0][i] = 'X';
				c[0][i+1] = 'X';
				c[1][i+1] = 'X';
				count++;
			}
			if(c[0][i+1] == '0' && c[1][i+1] == '0' && c[1][i] == '0'){
				c[1][i] = 'X';
				c[0][i+1] = 'X';
				c[1][i+1] = 'X';
				count++;
			}
		}
		System.out.println(count);
	}
	public static boolean isPrime(int n){
		if(n == 1) return false;
		if(n == 2 || n == 3) return true;
		for(int i = 2; i <= Math.sqrt(n); i++){
			if(n % i == 0) return false;
		}
		return true;
	}
	// tar の方が数字が大きいかどうか
	static boolean compare(String tar, String src) {
		if (src == null) return true;
		if (src.length() == tar.length()) {
			int len = tar.length();
			for (int i = 0; i < len; i++) {
				if (src.charAt(i) > tar.charAt(i)) {
					return false;
				} else if (src.charAt(i) < tar.charAt(i)) {
					return true;
				}
			}
			return tar.compareTo(src) > 0 ? true : false;
		} else if (src.length() < tar.length()) {
			return true;
		} else if (src.length() > tar.length()) {
			return false;
		}
		return false;
	}
	public static class Edge{
		int to;
		Edge(int to){
			this.to = to;
		}
	}
	public static void swap(long a, long b){
		long tmp = 0;
		if(a > b){
			tmp = a;
			a = b;
			b = tmp;
		}
	}
  static class Pair implements Comparable<Pair>{
    int first, second;
    Pair(int a, int b){
        first = a;
        second = b;
    }
    @Override
    public boolean equals(Object o){
        if (this == o) return true;
        if (!(o instanceof Pair)) return false;
        Pair p = (Pair) o;
        return first == p.first && second == p.second;
    }
    @Override
    public int compareTo(Pair p){
        return first == p.first ? second - p.second : first - p.first; //firstで昇順にソート
        //return (first == p.first ? second - p.second : first - p.first) * -1; //firstで降順にソート
        //return second == p.second ? first - p.first : second - p.second;//secondで昇順にソート
        //return (second == p.second ? first - p.first : second - p.second)*-1;//secondで降順にソート
    }
  }

  //繰り返し二乗法
  public static long pow(long x, long n){
    long ans = 1;
    while(n > 0){
      if((n & 1) == 1){
        ans = ans * x;
        ans %= mod;
      }
      x = x * x % mod;
      n >>= 1;
    }
    return ans;
  }

	public static long div(long x, long y){
		return (x*pow(y, mod-2))%mod;
	}

  //fac, inv, finvテーブルの初期化、これ使う場合はinitComb()で初期化必要
	public static  void initComb(){
		fac[0] = finv[0] = inv[0] = fac[1] = finv[1] = inv[1] = 1;
		for (int i = 2; i < size; ++i) {
			fac[i] = fac[i - 1] * i % mod;
			inv[i] = mod - (mod / i) * inv[(int) (mod % i)] % mod;
			finv[i] = finv[i - 1] * inv[i] % mod;
		}
	}

	//nCk % mod
	public static long comb(int n, int k){
		return fac[n] * finv[k] % mod * finv[n - k] % mod;
	}

	//n! % mod
	public static long fact(int n){
		return fac[n];
	}

	//(n!)^-1 with % mod
	public static long finv(int n){
		return finv[n];
	}

  static class UnionFind {
    int[] parent;
    public UnionFind(int size) {
      parent = new int[size];
      Arrays.fill(parent, -1);
    }
    public boolean unite(int x, int y) {
      x = root(x);
      y = root(y);
      if (x != y) {
        if (parent[y] < parent[x]) {
          int tmp = y;
          y = x;
          x = tmp;
        }
        parent[x] += parent[y];
        parent[y] = x;
        return true;
      }
      return false;
    }
    public boolean same(int x, int y) {
      return root(x) == root(y);
    }
    public int root(int x) {
      return parent[x] < 0 ? x : (parent[x] = root(parent[x]));
    }
    public int size(int x) {
      return -parent[root(x)];
    }
  }
	public static int upperBound(int[] array, int value) {
			 int low = 0;
			 int high = array.length;
			 int mid;
			 while( low < high ) {
					 mid = ((high - low) >>> 1) + low; // (high + low) / 2
					 if( array[mid] <= value ) {
							 low = mid + 1;
					 } else {
							 high = mid;
					 }
			 }
			 return low;
	 }
	 public static final int lowerBound(final int[] arr, final int value) {
    	int low = 0;
    	int high = arr.length;
    	int mid;
    	while (low < high){
        	mid = ((high - low) >>> 1) + low;    //(low + high) / 2 (オーバーフロー対策)
        	if (arr[mid] < value) {
          	low = mid + 1;
        	} else {
            high = mid;
        	}
    	}
    	return low;
		}
  //n,mの最大公約数
  public static long gcd(long n, long m){
    if(m > n) return gcd(m,n);
    if(m == 0) return n;
    return gcd(m, n%m);
  }
	//3要素のソート
	private class Pair2 implements Comparable<Pair2> {
		String s;
		int p;
		int index;
		public Pair2(String s, int p, int index) {
				this.s = s;
				this.p = p;
				this.index = index;
		}

		public int compareTo(Pair2 other) {
				if (s.equals(other.s)) {
						return other.p - this.p;
				}
				return this.s.compareTo(other.s);
		}
	}
	//c -> intに変換
public static int c2i(char c){
	if('A' <= c && c <= 'Z'){
		return c - 'A';
	}else{
		return c - 'a' + 26;
	}
}
// int -> charに変換
public static char i2c(int i){
	if(0 <= i && i < 26){
			return (char)(i + 'A');
	}else{
			return (char)(i + 'a' - 26);
	}
}

}


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

    }
}


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.util.ArrayList;
import java.io.InputStream;

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

    static class BObtainingTheString {
        public void solve(int testNumber, FastScanner br, PrintWriter pw) {
            int n = br.nextInt();
            String s = br.nextString();
            String t = br.nextString();
            char[] sarr = new char[n];
            char[] tarr = new char[n];
            int[] sAppear = new int[26];
            int[] tAppear = new int[26];
            for (int i = 0; i < s.length(); i++) {
                sarr[i] = s.charAt(i);
                tarr[i] = t.charAt(i);
                sAppear[s.charAt(i) - 'a']++;
                tAppear[t.charAt(i) - 'a']++;
            }
            for (int i = 0; i < 26; i++) {
                if (sAppear[i] != tAppear[i]) {
                    pw.println(-1);
                    pw.close();
                }
            }
            ArrayList<Integer> ans = new ArrayList<Integer>();
            for (int i = 0; i < n; i++) {
                char curr = tarr[i];
                for (int j = i + 1; j < n; j++) {
                    if (sarr[j] == curr) {
                        for (int k = j; k > i; k--) {
                            ans.add(k);
                            char temp = sarr[k - 1];
                            sarr[k - 1] = sarr[k];
                            sarr[k] = temp;
                        }
                        break;
                    }
                }
            }
            pw.println(ans.size());
            for (int e : ans) {
                pw.print(e + " ");
            }
            pw.close();
        }

    }

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

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

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

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

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

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

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

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

        }

    }
}


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

public class aaaaaaaaaaaaaaaa {
	public void run() throws Exception {
		Scanner file = new Scanner(System.in);
		int a = file.nextInt(), b= file.nextInt(), c = file.nextInt(), n = file.nextInt();
		a -= c;
		b -= c;
		if (a < 0 || b < 0) System.out.println(-1);
		else {
			int x = a + b + c;
			if (x >= n) System.out.println(-1);
			else System.out.println(n - x);
		}
	}

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

}


// discussed with rainboy
import java.io.*;
import java.util.*;

public class CF915E {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pw = new PrintWriter(System.out);
		int n = Integer.parseInt(br.readLine());
		int q = Integer.parseInt(br.readLine());
		TreeMap<Integer, Integer> mp = new TreeMap<>();
		int ans = 0;
		while (q-- > 0) {
			StringTokenizer st = new StringTokenizer(br.readLine());
			int l = Integer.parseInt(st.nextToken()) - 1;
			int r = Integer.parseInt(st.nextToken());
			int t = Integer.parseInt(st.nextToken());
			Map.Entry<Integer, Integer> e;
			int l_, r_;
			if (t == 1) {
				if ((e = mp.floorEntry(l)) != null && (r_ = e.getValue()) >= l) {
					l_ = e.getKey();
					ans -= r_ - l_;
					l = l_;
					r = Math.max(r, r_);
				}
				while ((e = mp.higherEntry(l)) != null && (l_ = e.getKey()) <= r) {
					r_ = e.getValue();
					ans -= r_ - l_;
					r = Math.max(r, r_);
					mp.remove(l_);
				}
				ans += r - l;
				mp.put(l, r);
			} else {
				r_ = l;
				if ((e = mp.floorEntry(l)) != null && (r_ = e.getValue()) > l) {
					l_ = e.getKey();
					if (l_ < l)
						mp.put(l_, l);
					else
						mp.remove(l_);
					ans -= r_ - l;
				}
				while ((e = mp.higherEntry(l)) != null && (l_ = e.getKey()) < r) {
					r_ = e.getValue();
					mp.remove(l_);
					ans -= r_ - l_;
				}
				if (r_ > r) {
					mp.put(r, r_);
					ans += r_ - r;
				}
			}
			pw.println(n - ans);
		}
		pw.close();
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.util.HashSet;
import java.util.StringTokenizer;

public class Main {
	public static String conv(String str) {
		boolean[] Arr = new boolean[26];
		for (int i = 0; i < str.length(); i++) {
			Arr[str.charAt(i) - 'a'] = true;
		}
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < 26; i++) {
			if (Arr[i])
				sb.append((char) (i + 'a'));
		}
		return "" + sb;
	}

	public static void main(String[] args) throws IOException, InterruptedException {
		PrintWriter pw = new PrintWriter(System.out);
		Scanner sc = new Scanner(System.in);
		HashSet<String> hs = new HashSet<String>();
		int[] Arr = new int[14];
		long max = 0;
		for (int i = 0; i < 14; i++) {
			Arr[i] = sc.nextInt();
		}

		for (int i = 0; i < 14; i++) {
			int[] arr = Arr.clone();

			long sum = 0;
			int r = arr[i];
			arr[i] = 0;
			for (int j = i + 1; j < arr.length && r > 0; j++) {
				arr[j]++;
				r--;
			}
			for (int j = 0; j < arr.length; j++) {
				arr[j] +=( r / 14);
				if (j + 1 <= (r % 14)) {
					arr[j]++;
				}
				if (arr[j] % 2 == 0) {
					sum += arr[j];
				}
			}
			max = Math.max(max, sum);

		}
		System.out.println(max);
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

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

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

	}
}