import java.util.*;

public class A741 {

	public static void main(String[] args){

		int n;

		A741 ob=new A741();

		Scanner scan=new Scanner(System.in);

		n=scan.nextInt();

		int[] arr= new int[n];

		for(int i=0;i<n;i++){
			arr[i]=scan.nextInt();
		}

		boolean[] tv=new boolean[n];

		int i=0;
		int max=1;

		for(;i<n;i++){
			if(!tv[i]){

				ArrayList<Integer> al=new ArrayList<>();

				al.add(i+1);
				int res=0;

				while(!tv[i]){

					al.add(arr[i]);
					tv[i]=true;
					i=arr[i]-1;

				}

				if(al.get(0)==al.get(al.size()-1))
				{
					res=al.size()-1;

					if(res%2==0)
						res/=2;

					max=ob.lcm(max,res);

				}

				else {

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

			}

		}

		System.out.println(max);
	}

	int lcm(int a,int b){

		int min,max;

		if(a>b)
		{
		max=a;
		min=b;
		}
		else
		{
		max=b;
		min=a;
		}

		/*
		To find the maximum and minimum numbers, you can also use
		int max=a>b?a:b;
		int min=a<b?a:b;
		*/
		 int x,lcm=1;

		for(int i=1;i<=min;i++)
		   {
		    x=max*i; //finding multiples of the maximum number
		    if(x%min==0) //Finding the multiple of maximum number which is divisible by the minimum number.
		     {
		      lcm=x; //making the 1st multiple of maximum number as lcm, which is divisible by the minimum number
		      break; //exiting from the loop, as we don’t need anymore checking after getting the LCM
		     }
		    }
		return lcm;
}
}


import java.util.*;
public class Solution
{
	static Scanner sc = new Scanner(System.in);
	public static int solve()
	{
		int n = sc.nextInt(), pos = 0;

		for(int i=0;i<n;i++)
			pos += Math.abs(sc.nextInt());

		return pos;
	}

	public static void main(String args[])
	{
		System.out.println(solve());
	}
}


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

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

    static class TaskD {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int x = in.nextInt();
            int y = in.nextInt();
            int z = in.nextInt();
            int x1 = in.nextInt();
            int y1 = in.nextInt();
            int z1 = in.nextInt();

            int a1 = in.nextInt();
            int a2 = in.nextInt();
            int a3 = in.nextInt();
            int a4 = in.nextInt();
            int a5 = in.nextInt();
            int a6 = in.nextInt();

            int sum = 0;
            if (y < 0) {
                sum += a1;
            }
            if (y > y1) {
                sum += a2;
            }
            if (z < 0) {
                sum += a3;
            }
            if (z > z1) {
                sum += a4;
            }
            if (x < 0) {
                sum += a5;
            }
            if (x > x1) {
                sum += a6;
            }
            out.println(sum);
        }

    }

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

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

        public String nextLine() {
            try {
                return reader.readLine();
            } catch (IOException e) {
                return null;
            }
        }

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

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

    }
}


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

public class B {

	public static void main(String[] args) {
		InputReader in = new InputReader(System.in);
		PrintWriter out = new PrintWriter(System.out);
		B solver = new B();
		solver.solve(1, in, out);
		out.close();

	}

	public void solve(int testNumber, InputReader in, PrintWriter out) {

		int n = in.nextInt();
		float t = in.nextInt();

		float[][] dp = new float[n + 1][n + 1];

		dp[0][0] = t;
		int count = 0;

		for(int i = 0; i < n; i++) {
			for(int j = 0; j <= i; j++) {
				float X = dp[i][j];
				if(X >= 1) {
					count++;
					// dp[i][j] = 1;
					X -= 1;
					dp[i + 1][j] += X/2;
					dp[i + 1][j + 1] += X/2;
				}
			}

		}

		out.println(count);

	}

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

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

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

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

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

	}
}


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

public class GuessTheTree {

	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;
	boolean eof;

	boolean solve() throws IOException {
		int n = nextInt();
		int initN = n;
		List<Integer> szList = new ArrayList<>();
		int leaves = 0;

		for (int i = 0; i < n; i++) {
			int x = nextInt();
			if (x == 1) {
				leaves++;
			} else {
				szList.add(x);
			}
		}

		n = szList.size();

		if (leaves <= n) {
			return false;
		}

		if (n == 0) {
			return true;
		}

		Collections.sort(szList);
		Collections.reverse(szList);

		int[] sz = new int[n];
		for (int i = 0; i < sz.length; i++) {
			sz[i] = szList.get(i);
		}

		if (sz[0] != initN) {
			return false;
		}

		int[] maskCnt = new int[1 << n];
		int[] maskSum = new int[1 << n];
		for (int i = 0; i < n; i++) {
			maskCnt[1 << i] = 1;
			maskSum[1 << i] = sz[i];
		}

		for (int mask = 1; mask < (1 << n); mask++) {
			int low = Integer.lowestOneBit(mask);
			maskCnt[mask] = maskCnt[low] + maskCnt[mask ^ low];
			maskSum[mask] = maskSum[low] + maskSum[mask ^ low];
		}

		boolean[][][] dp = new boolean[n + 1][leaves + 1][1 << n];
		// current node, unassigned leaves, unassigned nodes

		final int ALL = (1 << n) - 1;

		dp[0][leaves][ALL ^ 1] = true;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j <= leaves; j++) {
				for (int mask = 0; mask < (1 << n); mask++) {
					if (!dp[i][j][mask] || test(mask, i)) {
						continue;
					}
					for (int sub = mask; ; sub = (sub - 1) & mask) {
						int leavesHere = sz[i] - 1 - maskSum[sub];
						if (leavesHere >= 0 && leavesHere <= j
								&& leavesHere + maskCnt[sub] >= 2) {
							dp[i + 1][j - leavesHere][mask ^ sub] = true;
						}
						if (sub == 0) {
							break;
						}
					}
				}
			}
		}

		return dp[n][0][0];

	}

	static boolean test(int mask, int i) {
		return ((mask >> i) & 1) == 1;
	}

	void inp() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		out.println(solve() ? "YES" : "NO");
		out.close();
	}

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

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

	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			eof = true;
			return null;
		}
	}

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

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

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


import java.io.*;

/**
 * Created by DELL on 14-Nov-15.1 0
 */
public class Hopscotch
{
    public static void main(String ar[])
    {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;

        BufferedReader in = new BufferedReader(new InputStreamReader(inputStream));
        PrintWriter out = new PrintWriter(outputStream);

        Hopscotch demo = new Hopscotch();
        demo.solve(in, out);

        out.close();
    }

    public void solve(BufferedReader in, PrintWriter out)
    {
        try
        {
            String tokens[] = in.readLine().split(" ");
            int side = Integer.parseInt(tokens[0]);
            int x = Integer.parseInt(tokens[1]);
            int y = Integer.parseInt(tokens[2]);
            out.println(taskB(side, x, y));
        } catch (IOException e)
        {
            e.printStackTrace();
        }
    }

    public long taskB(int side, int x, int y)
    {
        if (x == side || x == -side || y % side == 0)
        {
            return -1;
        }
        long yAbove = 0;
        long yBelow = 0;
        long iteration = 0;
        long stone = 0;
        while (true)
        {
            iteration++;
            stone = (iteration == 1 || iteration % 2 == 0) ? stone + 1 : stone + 2;
            yBelow = yAbove;
            yAbove += side;
            if ((y > yBelow && y < yAbove))
            {
                if (iteration == 1 || iteration % 2 == 0)
                {
                    if (x < side / 2.0 && x > -side / 2.0)
                    {
                        return stone;
                    }
                }
                else
                {
                    if (x == 0)
                    {
                        return -1;
                    }
                    else if (x < side && x > 0)
                    {
                        return stone;
                    }
                    else if (x > -side && x < 0)
                    {
                        return stone - 1;
                    }
                }
            }
            else if ((y < yBelow && y < yAbove) || y == yBelow || y == yAbove)
            {
                return -1;
            }
        }
    }
}


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

public class Main {
	public static void main(String[] args){
		Scanner cin=new Scanner(System.in);
		while(cin.hasNextInt()){
			BigInteger res1,res2,base,b1,b2;
			int n1,n2,i;
			BigInteger num1[]=new BigInteger[15];
			BigInteger num2[]=new BigInteger[15];
			n1=cin.nextInt();
			b1=cin.nextBigInteger();
			base=new BigInteger("1");
			res1=new BigInteger("0");
			for(i=0;i<n1;i++){
				num1[i]=cin.nextBigInteger();
			}
			for(i=n1-1;i>=0;i--){
				res1=res1.add(base.multiply(num1[i]));
				base=base.multiply(b1);
			}
			n2=cin.nextInt();
			b2=cin.nextBigInteger();
			base=new BigInteger("1");
			res2=new BigInteger("0");
			for(i=0;i<n2;i++){
				num2[i]=cin.nextBigInteger();
			}
			for(i=n2-1;i>=0;i--){
				res2=res2.add(base.multiply(num2[i]));
				base=base.multiply(b2);
			}
			if(res1.compareTo(res2)==0) System.out.println("=");
			else if(res1.compareTo(res2)<0) System.out.println("<");
			else System.out.println(">");
		}
	}
}


import java.util.*;

 public class Solution{

    public static void main(String args[]){

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        String abc=sc.nextLine();
        String str = sc.nextLine();

        char ch[] = str.toCharArray();
        int arr[] = new int[ch.length];
        int vrr[] = new int[3];
        for(int i=0;i<ch.length;i++){

            if(ch[i]=='B'){

                arr[i] = 1;
                vrr[arr[i]-1]++;
            }

            if(ch[i]=='R') {

            	arr[i] = 3;vrr[arr[i]-1]++;
            }

            if(ch[i]=='G') {

            	arr[i] = 2;vrr[arr[i]-1]++;
            }

        }

        if(n!=1){

        int c[] = new int[3];

        Arrays.fill(c,0);
        int sum=0 , f=0;

        for(int i=0;i<ch.length;i++){

            for(int j=0;j<ch.length;j++){

                sum = 0;
                if(i==j) {
                	continue;
                }

                if(i!=j){

                   sum = arr[j]^arr[i];
                 //  System.out.println("xor is "+sum);
                   if(sum==0) {

                	   c[arr[i]-1]++;

                	 //  System.out.println(" c["+(arr[i]-1)+"] is  "+c[arr[i]-1]);

                   }
                   else {
                   c[sum-1]++;

                //   System.out.println(" c["+(sum-1)+"] is  "+c[sum-1]);
                   }
               }

                if(c[0]>0 && c[1]>0 && c[2]>0) {

                	f = 3;
                	break;

                }
            }

            if((c[0]>0 && c[1]>0 && c[2]==0 ) ||  (c[0]==0 && c[1]>0 && c[2]>0 ) || (c[0]>0 && c[1]==0 && c[2]>0 ) ) {

            	f = 2;

            }

        }

        int cc=0 ,mm=-1;;
      if(f==2) {

    	  if( vrr[0]>=2) {
    		  System.out.print("GR");
    		 cc = -1;
      }

    	  if( vrr[1]>=2 && cc!=-1) {
    		  System.out.print("BR");
    		  cc=-1;
      }

    	  if( vrr[2]>=2 && cc!=-1) {
    		  System.out.print("BG");
      }

    	 mm=0;
      }

        if(mm==-1) {

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

    	   if(c[i]>0 && i==0) {
    		   System.out.print("B");
    	   }

    	   if(c[i]>0 && i==1) {
    		   System.out.print("G");
    	   }

    	   if(c[i]>0 && i==2) {
    		   System.out.print("R");
    	   }

       }

      }

    }
    else{
    System.out.println(str);
    }

    }
}


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

public class E_1228 {

    static int n;
    static long k;
    static long[][] dp;
    static long[] kPow;
    static long[] k1Pow;
    static long[][] C;
    static long mod = (long) (1e9 + 7);

    static void prec() {
        kPow = new long[n + 1];
        k1Pow = new long[n + 1];
        kPow[0] = 1;
        k1Pow[0] = 1;
        for (int i = 1; i <= n; i++) {
            kPow[i] = (kPow[i - 1] * k) % mod;
            k1Pow[i] = (k1Pow[i - 1] * (k - 1)) % mod;
        }

        C = new long[n + 1][n + 1];
        C[0][0] = 1;
        for (int i = 1; i <= n; i++) {
            C[i][0] = C[i][i] = 1;
            for (int j = 1; j < i; j++) {
                C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % mod;
            }
        }
    }

    static long mod(long x) {
        x %= mod;
        if (x < 0) x += mod;
        return x;
    }

    static void solve(FastReader in, PrintWriter out) {
        n = in.nextInt();
        k = in.nextInt();

        prec();

        dp = new long[n + 1][n + 1];
        dp[0][0] = 1;
        for (int r = 1; r <= n; r++) {
            dp[r][0] = dp[r - 1][0] * mod(kPow[n] - k1Pow[n]) % mod;
        }
        for (int c = 1; c <= n; c++) {
            dp[1][c] = kPow[n - c];
        }

        for (int r = 2; r <= n; r++) {
            for (int c = 1; c <= n; c++) {
                dp[r][c] = k1Pow[c] * mod(kPow[n - c] - k1Pow[n - c]) % mod * dp[r - 1][c] % mod;
                for (int c0 = 1; c0 <= c; c0++) {
                    dp[r][c] = (dp[r][c] + kPow[n - c] * C[c][c0] % mod * k1Pow[c - c0] % mod * dp[r - 1][c - c0] % mod) % mod;
                }
            }
        }

        out.println(dp[n][n]);
    }

    public static void main(String[] args) {
        FastReader in = new FastReader(System.in);
//        FastReader in = new FastReader(new FileInputStream("input.txt"));
        PrintWriter out = new PrintWriter(System.out);
//        PrintWriter out = new PrintWriter(new FileOutputStream("output.txt"));

        int q = 1;

        while (q-- > 0)
            solve(in, out);

        out.close();
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        FastReader(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
        }

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

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

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

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                st = new StringTokenizer(nextLine());
            }
            return st.nextToken();
        }

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


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.util.StringTokenizer;
import java.io.PrintWriter;
import java.io.*;
import java.lang.*;
public class Ideone
{
    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

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

    int x, y;
    public aksh(int a, int b)
    {
        x = a;
        y = b;
    }
}
static long power(long x,long y)
{
    long res = 1;      // Initialize result

      // Update x if it is more than or
                // equal to p

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y%2==1)
            res = (res*x);

        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x);
    }
    return res;
}

    public static void main (String[] args) throws java.lang.Exception
    {
        // your code goes here
        FastReader sc=new FastReader();
        String s=sc.next();
        String t=sc.next();
        int ans=Integer.MIN_VALUE;
        for(int i=0;i<s.length();i++)
        {
            for(int j=i;j<s.length();j++)
            {
                int pos=0;
                for(int k=0;k<s.length();k++)
                {
                    if(i<=k && k<= j)
                        continue;

                    if(pos<t.length() && s.charAt(k)==t.charAt(pos))
                        pos++;
                }

                if(pos==t.length())
                    ans=Math.max(ans,j-i+1);
            }
        }
        System.out.println(Math.max(ans,0));

    }
}


import java.util.*;
import java.io.*;
public class Main {
    public static long mod= (long) (1e9 +7);
    public static void main(String args[]){
        InputReader s= new InputReader(System.in);
        OutputStream outputStream= System.out;
        PrintWriter out= new PrintWriter(outputStream);
        int n= s.nextInt();
        //out.print(Integer.toString(123,16));
        int sum=0;
        for(int i=2;i<n;i++){
            int y=n;
            for(int j=0;;j++){
                int x= y%i;
                sum= sum+ x;
                y= y/i;
                if(y==0){
                    break;
                }
            }
            //out.println(sum);
        }
        //out.println(sum);
        int div= gcd(sum,n-2);
        out.println((sum/div)+"/"+((n-2)/div));
        out.close();
    }
    public static int sumDigits(String x){
        int sum= 0;
        for(int i=0;i<x.length();i++){
            sum= sum+ x.charAt(i)-48;
        }
        return sum;

    }
    static class InputReader {

        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream inputstream) {
          reader = new BufferedReader(new InputStreamReader(inputstream));
          tokenizer = null;
        }

        public String nextLine(){
            String fullLine=null;
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                  fullLine=reader.readLine();
                } catch (IOException e) {
                  throw new RuntimeException(e);
                }
                return fullLine;
              }
              return fullLine;
        }
        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 long nextLong() {
              return Long.parseLong(next());
            }
        public int nextInt() {
          return Integer.parseInt(next());
        }
      }
    public static int gcd(int number1, int number2) {
        if(number2 == 0){
            return number1;
        }
        return gcd(number2, number1%number2);
    }
    public static int combinations(int n,int r){
        if(n==r) return 1;
        if(r==1) return n;
        if(r==0) return 1;
        return combinations(n-1,r)+ combinations(n-1,r-1);
    }

    public static int expo(int a, int b){
        if (b==1)
            return a;
        if (b==2)
            return a*a;

        if (b%2==0){
                return expo(expo(a,b/2),2);
        }
        else{
            return a*expo(expo(a,(b-1)/2),2);
        }
    }

    public static void sieve(int N){
        int arr[]= new int[N+1];
        for(int i=2;i<Math.sqrt(N);i++){
            if(arr[i]==0){
                for(int j= i*i;j<= N;j= j+i){
                    arr[j]=1;
                }
            }
        }
        // All the i for which arr[i]==0 are prime numbers.
    }
}


import java.util.Scanner;

public class a617 {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int steps = 0;
		if (x%5 == 0) {
			steps += (int)Math.floor(x/5);
		}else{
			steps += (int)Math.floor(x/5) + 1;
		}
		System.out.println(steps);
	}
}


import java.util.Arrays;
import java.util.Scanner;

/*
1 2 1000

2 2 1000

5 3 1103

999 99 1000000000

 */

public class d {

	static int n;
	static int k;
	static int m;

	static long[][] memo;

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

		n = in.nextInt();
		k = in.nextInt();
		m = in.nextInt();
		in.close();

		memo = new long[n+1][k];
		for(int curr = 0; curr < memo.length; ++curr)
		{
			Arrays.fill(memo[curr], -1);
		}

		System.out.println(go(1, 0, 1));
	}

	static long go(int place, int mod, int tens)
	{
		if(place == n+1) return 0;

		if(memo[place][mod] != -1)
			return memo[place][mod];

		long ret = 0;

		for(int curr = place == n?1:0; curr < 10; ++curr)
		{
			int nmod = (mod + curr*tens) %k;

			if(curr != 0 && nmod == 0)
			{
				//System.out.print(place +" " +curr +" " +mod +" ");
				long r = 1;
				for(int loc = place+1; loc < n; ++loc)
				{
					r = (r*10)%m;
				}
				if(place != n)
				{
					r = (r*9)%m;
				}
				//System.out.println(r);
				ret = (ret + r)%m;
			}
			else
			{
				ret = (ret + go(place+1, nmod, (tens*10)%k))%m;
			}
		}

		return memo[place][mod] = ret;
	}
}


import java.util.Scanner;

/**
 * http://codeforces.com/problemset/problem/465/A
 *
 */
public class A {

    public static void main(String[] args) {
        new A().doJob();
    }

    private void doJob() {
        try (Scanner scanner = new Scanner(System.in)) {
            int n = scanner.nextInt();
            char[] array = scanner.next().toCharArray();
            int count = 0;
            for (int i = 0; i < n; i++) {
                count++;
                if (array[i] == '0') {
                    break;
                }
            }
            System.out.println(count);
        }
    }
}


import java.util.Scanner;

public class CFProblemC {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner input = new Scanner(System.in);
		long  sum = input.nextLong();
		long xOr = input.nextLong();
		long xOrCpy = xOr;
		long  sumCpy =  sum;
		long[] xOrBool = new long[60];
//		long[] xOrSum = new long[60];
		int a = 59;
		while(xOr > 0){
			xOrBool[a] = (xOr%2);
			a--;
			xOr /= 2;
		}
//		a = 0;
//		while(sum > 0){
//			xOrSum[a] = (sum%2);
//			a++;
//			sum /= 2;
//		}

		long decisions  = 0;

		for(int b = 0; b < 60; b++){
//			System.out.println(sum);
			if(xOrBool[b] == 1L){
				decisions++;
				sum -= (long)(Math.pow(2, 59-b)+.5);
			}
			else{
				if(sum >= (long)(Math.pow(2, 60-b)+.5)){
					sum -= (long)(Math.pow(2, 60-b)+.5);
				}
			}
		}
//		System.out.println(sum);
		int zeroValid = (xOrCpy == sumCpy)?2:0 ;

		if(sum == 0){
			System.out.println((long)(Math.pow(2L, decisions)+.5)-zeroValid);
		}
		else{
			System.out.println(0);
		}

//		for(int b  = 0; b < 60; b++){
//
//		}

	}

}


/*
 * 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 Centrino
 */
import java.util.*;
public class JavaCourse {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
    Scanner sc = new Scanner (System.in);
    int x = sc.nextInt();
    int count =0;  int z=0,c=0;
    int i,r=x;
    boolean f =true;
    while(Math.sqrt(x)==(int)Math.sqrt(x)&&x>1){
    x =(int) Math.sqrt(x);count++;
    }
        for ( i =(int) Math.sqrt(x); i>1; i--) {
            z = i*i;
        while(x%(z)==0){
        count++;
        x /= i;
        f=false;
        }
           }
        if(f)
        System.out.println(x+" "+(count));
        else
        System.out.println(x+" "+(count+1));
    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.io.Closeable;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.math.BigInteger;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) throws Exception {
        Thread thread = new Thread(null, new TaskAdapter(), "", 1 << 29);
        thread.start();
        thread.join();
    }

    static class TaskAdapter implements Runnable {
        @Override
        public void run() {
            InputStream inputStream = System.in;
            OutputStream outputStream = System.out;
            FastInput in = new FastInput(inputStream);
            FastOutput out = new FastOutput(outputStream);
            DRadioTowers solver = new DRadioTowers();
            solver.solve(1, in, out);
            out.close();
        }
    }

    static class DRadioTowers {
        int mod = 998244353;
        Combination comb = new Combination((int) 1e6, mod);
        CachedPow pow = new CachedPow(2, mod);

        public void solve(int testNumber, FastInput in, FastOutput out) {
            int n = in.ri();
            long prob = 0;
            for (int i = 1; i <= n; i++) {
                if ((n - i) % 2 != 0) {
                    continue;
                }
                int m = (n - i) / 2;
                long way = comb.combination(m + i - 1, i - 1);
                prob += way * pow.inverse(n) % mod;
            }
            prob %= mod;
            out.println(prob);
        }

    }

    static class Combination implements IntCombination {
        final Factorial factorial;
        int modVal;

        public Combination(Factorial factorial) {
            this.factorial = factorial;
            this.modVal = factorial.getMod();
        }

        public Combination(int limit, int mod) {
            this(new Factorial(limit, mod));
        }

        public int combination(int m, int n) {
            if (n > m || n < 0) {
                return 0;
            }
            return (int) ((long) factorial.fact(m) * factorial.invFact(n) % modVal * factorial.invFact(m - n) % modVal);
        }

    }

    static class FastOutput implements AutoCloseable, Closeable, Appendable {
        private static final int THRESHOLD = 1 << 13;
        private final Writer os;
        private StringBuilder cache = new StringBuilder(THRESHOLD * 2);

        public FastOutput append(CharSequence csq) {
            cache.append(csq);
            return this;
        }

        public FastOutput append(CharSequence csq, int start, int end) {
            cache.append(csq, start, end);
            return this;
        }

        private void afterWrite() {
            if (cache.length() < THRESHOLD) {
                return;
            }
            flush();
        }

        public FastOutput(Writer os) {
            this.os = os;
        }

        public FastOutput(OutputStream os) {
            this(new OutputStreamWriter(os));
        }

        public FastOutput append(char c) {
            cache.append(c);
            afterWrite();
            return this;
        }

        public FastOutput append(long c) {
            cache.append(c);
            afterWrite();
            return this;
        }

        public FastOutput append(String c) {
            cache.append(c);
            afterWrite();
            return this;
        }

        public FastOutput println(long c) {
            return append(c).println();
        }

        public FastOutput println() {
            return append(System.lineSeparator());
        }

        public FastOutput flush() {
            try {
                os.append(cache);
                os.flush();
                cache.setLength(0);
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
            return this;
        }

        public void close() {
            flush();
            try {
                os.close();
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        }

        public String toString() {
            return cache.toString();
        }

    }

    static class FastInput {
        private final InputStream is;
        private byte[] buf = new byte[1 << 13];
        private int bufLen;
        private int bufOffset;
        private int next;

        public FastInput(InputStream is) {
            this.is = is;
        }

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

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

        public int ri() {
            return readInt();
        }

        public int readInt() {
            int sign = 1;

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

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

            return val;
        }

    }

    static class DigitUtils {
        private DigitUtils() {
        }

        public static int negate(int x, int mod) {
            return x == 0 ? 0 : mod - x;
        }

    }

    static class Factorial {
        int[] fact;
        int[] inv;
        int mod;

        public int getMod() {
            return mod;
        }

        public Factorial(int[] fact, int[] inv, int mod) {
            this.mod = mod;
            this.fact = fact;
            this.inv = inv;
            fact[0] = inv[0] = 1;
            int n = Math.min(fact.length, mod);
            for (int i = 1; i < n; i++) {
                fact[i] = i;
                fact[i] = (int) ((long) fact[i] * fact[i - 1] % mod);
            }
            inv[n - 1] = BigInteger.valueOf(fact[n - 1]).modInverse(BigInteger.valueOf(mod)).intValue();
            for (int i = n - 2; i >= 1; i--) {
                inv[i] = (int) ((long) inv[i + 1] * (i + 1) % mod);
            }
        }

        public Factorial(int limit, int mod) {
            this(new int[limit + 1], new int[limit + 1], mod);
        }

        public int fact(int n) {
            return fact[n];
        }

        public int invFact(int n) {
            return inv[n];
        }

    }

    static interface IntCombination {
    }

    static class CachedPow {
        private int[] first;
        private int[] second;
        private int mod;
        private int powMod;
        private static int step = 16;
        private static int limit = 1 << step;
        private static int mask = limit - 1;

        public CachedPow(int x, int mod) {
            this.mod = mod;
            this.powMod = mod - 1;
            first = new int[limit];
            second = new int[Integer.MAX_VALUE / limit + 1];
            first[0] = 1;
            for (int i = 1; i < first.length; i++) {
                first[i] = (int) ((long) x * first[i - 1] % mod);
            }
            second[0] = 1;
            long step = (long) x * first[first.length - 1] % mod;
            for (int i = 1; i < second.length; i++) {
                second[i] = (int) (second[i - 1] * step % mod);
            }
        }

        public int pow(int exp) {
            return (int) ((long) first[exp & mask] * second[exp >> step] % mod);
        }

        public int inverse(int exp) {
            return pow(DigitUtils.negate(exp, powMod));
        }

    }
}


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

/**
 *
 * @author Antonio "Teo" Alurralde
 */
public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(br.readLine());
    int m = Integer.parseInt(br.readLine());
    int bs = n;
    int sum = 0;
    int max = 0;
    int a, min;
    while(n-->0) {
      a = Integer.parseInt(br.readLine());
      sum += a;
      max = Math.max(max, a);
    }
    min = Math.max((sum+m)/bs + ((sum+m)%bs>0?1:0), max);
    System.out.printf("%d %d", min, max + m);
  }
}


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

public class D {
	final long MOD = (long)(1e9+7);
	long p,k;
	void readInput() throws NumberFormatException, IOException{
		//BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		Scanner sc = new Scanner(System.in);
		p = sc.nextLong();
		k = sc.nextLong();
	}

	public static long powmod(long a, long x, long n){
		long res = 1;
		a = a % n;
		while(x>0){
			if ( x % 2 == 1)
				res = (res*a) %n;
			a = (a*a) %n;
			x = x >> 1;
		}
		return res;
	}

	void solve(){
		long ssol = 0;
		if (k==0)
			ssol = powmod(p, p-1, MOD);
		else if (k==1)
			ssol = powmod(p, p, MOD);
		else {
			int ord = 1;
			long q = k;
			while(q!=1)
			{
				q = (q*k) % p;
				if (q<0) q+= p;
				ord++;
			}
			ssol = powmod(p, (p-1)/ord, MOD);
		}
		System.out.println(ssol);
	}

	public static void main(String[] args) throws NumberFormatException, IOException {
		D a = new D();
		a.readInput();
		a.solve();
	}

}


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

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

	FastReader in = new FastReader();
	PrintWriter out = new PrintWriter(System.out);
	void run(){
		work();
		out.flush();
	}
	long mod=1000000007;
	long gcd(long a,long b) {
		return b==0?a:gcd(b,a%b);
	}
	void work() {
		int n=in.nextInt();
		int m=in.nextInt();
		long r1=2,r0=2;
		for(int i=1;i<n;i++) {
			long t=r1+r0;
			r0=r1;
			r1=t%mod;
		}
		long c1=2,c0=2;
		for(int i=1;i<m;i++) {
			long t=c1+c0;
			c0=c1;
			c1=t%mod;
		}
		long ret=(c1+r1-2)%mod;
		if(ret<0) {
			ret+=mod;
		}
		out.println(ret);
	}

	private int find(int v,Node node,int l,int r) {
		if(l==r)return l;
		int m=(l+r)/2;
		if(node.lNode.cnt>=v) {
			return find(v,node.lNode,l,m);
		}else {
			return find(v-node.lNode.cnt,node.rNode,m+1,r);
		}
	}
	private void insert(int v, Node node, int l, int r) {
		node.cnt++;
		if(l==r)return;
		if(node.lNode==null)node.lNode=new Node(0);
		if(node.rNode==null)node.rNode=new Node(0);
		int m=(l+r)/2;
		if(v<=m) {
			insert(v,node.lNode,l,m);
		}else {
			insert(v,node.rNode,m+1,r);
		}
	}

	class Node{
		Node lNode;
		Node rNode;
		int cnt;
		Node(int c){
			cnt=c;
		}
	}
}

class FastReader
{
	BufferedReader br;
	StringTokenizer st;

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

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

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

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


import java.util.*;
import java.io.*;
public class codeforces {
    public static void main(String[] args) throws Exception {
        Scanner in=new Scanner(System.in);
        int A=in.nextInt();
        int B=in.nextInt();
        int C=in.nextInt();
        int N=in.nextInt();
        int k=N-(A+B-C);
        if(k<1 || C>A || C>B)
              System.out.println("-1");
        else{
            System.out.println(k);
        }

        in.close();
        return;
    }
}


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

public class B {
	public static void main(String args[]) throws Exception{
		long w = readLong();
		long m = readLong();
		long k = readLong();
		w /= k;
		long ans = 0;
		while(true){
			int s = Long.toString(m).length();
			long numb = (long) Math.pow(10, s);
			long a = numb-m;
			if(a*s < w){
				w -= a*s;
				m = numb;
				ans += a;
			}
			else{
				ans+= (w/(s));
				break;
			}
		}
		System.out.println(ans);
	}
	static BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
	static StringTokenizer st = new StringTokenizer(" ");
	static String readString() throws Exception{
		while(!st.hasMoreTokens()){
			st = new StringTokenizer(stdin.readLine());
		}
		return st.nextToken();
	}
	static int readInt() throws Exception {
		return Integer.parseInt(readString());
	}
	static long readLong() throws Exception {
		return Long.parseLong(readString());
	}
}


/* 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
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		MyScanner sc = new MyScanner();
        long n = sc.nextLong();
        long a = sc.nextLong();
        long b = sc.nextLong();
        long p = sc.nextLong();
        long q = sc.nextLong();
        long LCD = a * b / GCD(a, b);
        //System.out.println(a * b + " " + GCD(a,b));
        //System.out.println(LCD);
        long res = (n / a) * p + (n / b) * q;
        if (p > q){
            res -= q * (n / LCD);
        }else{
            res -= p * (n / LCD);
        }
        System.out.println(res);
	}

    public static long GCD(long a, long b){
        while (a > 0){
            long t = a;
            a = b % a;
            b = t;
        }
        return b;
    }
	    //-----------PrintWriter for faster output---------------------------------
   public static PrintWriter out;

   //-----------MyScanner class for faster input----------
   public 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.*;
import java.math.BigInteger;
import java.util.*;

public class Template implements Runnable {

    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok = new StringTokenizer("");

    void init() throws FileNotFoundException {
        try {
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");
        } catch (Exception e) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        }
    }

    String readString() throws IOException {
        while (!tok.hasMoreTokens()) {
            try {
                tok = new StringTokenizer(in.readLine(), " :");
            } catch (Exception e) {
                return null;
            }
        }
        return tok.nextToken();
    }

    int readInt() throws IOException {
        return Integer.parseInt(readString());
    }

    int[] readIntArray(int size) throws IOException {
        int[] res = new int[size];
        for (int i = 0; i < size; i++) {
            res[i] = readInt();
        }
        return res;
    }

    long readLong() throws IOException {
        return Long.parseLong(readString());
    }

    double readDouble() throws IOException {
        return Double.parseDouble(readString());
    }

    <T> List<T>[] createGraphList(int size) {
        List<T>[] list = new List[size];
        for (int i = 0; i < size; i++) {
            list[i] = new ArrayList<>();
        }
        return list;
    }

    public static void main(String[] args) {
        new Template().run();
        // new Thread(null, new Template(), "", 1l * 200 * 1024 * 1024).start();
    }

    long timeBegin, timeEnd;

    void time() {
        timeEnd = System.currentTimeMillis();
        System.err.println("Time = " + (timeEnd - timeBegin));
    }

    long memoryTotal, memoryFree;

    void memory() {
        memoryFree = Runtime.getRuntime().freeMemory();
        System.err.println("Memory = " + ((memoryTotal - memoryFree) >> 10)
                + " KB");
    }

    public void run() {
        try {
            timeBegin = System.currentTimeMillis();
            memoryTotal = Runtime.getRuntime().freeMemory();
            init();
            solve();
            out.close();
            if (System.getProperty("ONLINE_JUDGE") == null) {
                time();
                memory();
            }
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(-1);
        }
    }

    void solve() throws IOException {
        int n = readInt();
        int m = readInt();
        int all = readInt();
        int k = readInt();
        boolean[][] alt = new boolean[n][m];
        while (all-- > 0) {
            alt[readInt() - 1][readInt() - 1] = true;
        }
        int ans = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                for (int i1 = i; i1 < n; i1++) {
                    for (int j1 = j; j1 < m; j1++) {
                        int cnt = 0;
                        for (int ii = i; ii <= i1; ii++) {
                            for (int jj = j; jj <= j1; jj++) {
                                if (alt[ii][jj]) cnt++;
                            }
                        }
                        if (cnt >= k) {
                            ans++;
                        }
                    }
                }
            }
        }
        out.println(ans);

    }

}


/**
 * @(#)Game.java
 *
 *
 * @author
 * @version 1.00 2016/8/24
 */

import java.util.Scanner;
public class Game {
	public static void main(String[] args){
		Scanner mch = new Scanner(System.in);
		long a = mch.nextLong();
		a = a%2;
		System.out.print(2-a);
	}

}


import java.util.Scanner;
public class JavaApplication2 {
    public static void main(String[] args) {
        char []a,s;
    Scanner f=new Scanner(System.in);
           String g;
   g=f.next();
           a=new char[g.length()];
        for(int i=0;i<g.length();i++)
             a[i]=g.charAt(i);
         s=new char[4];
         for(int i=0;i<4;i++)
             s[i]=a[i];
         int i=4;
        while(s[0]=='!')
        {s[0]=a[i];
        i+=4;}
        i=5;
        while(s[1]=='!')
        {s[1]=a[i];
        i+=4;}
         i=6;
         while(s[2]=='!')
        {s[2]=a[i];
        i+=4;}
         i=7;
         while(s[3]=='!')
        {s[3]=a[i];
        i+=4;}
  int k[]=new int[4];
 for(int x=0;x<4;x++)
     k[x]=0;
      for(i=0;i<g.length();i+=4)
         if(a[i]!=s[0])
           k[0]++;
      for(i=1;i<g.length();i+=4)
         if(a[i]!=s[1])
           k[1]++;
      for(i=2;i<g.length();i+=4)
         if(a[i]!=s[2])
           k[2]++;
      for(i=3;i<g.length();i+=4)
         if(a[i]!=s[3])
           k[3]++;

     for(i=0;i<4;i++)
             if(s[i]=='R')
                 System.out.print(k[i]+" ");
     for(i=0;i<4;i++)
             if(s[i]=='B')
                 System.out.print(k[i]+" ");
   for(i=0;i<4;i++)
            if(s[i]=='Y')
                 System.out.print(k[i]+" ");
   for(i=0;i<4;i++)
            if(s[i]=='G')
                 System.out.print(k[i]);    }

}


import java.util.*;

public class helloWorld
{
	public static void main(String[] args)
	{
		Scanner in = new Scanner(System.in);
		String str = in.next();
		int n = Integer.parseInt( str.substring(0, 2) );
		int m = Integer.parseInt( str.substring(3, 5) );
		int ans = 0;

		for(int i = n; i < 24; i++) {
			int a = (i%10) * 10 + i/10;
			if(a < 60 && (i != n || a >= m)) {
				ans = (i-n)*60 + a-m;
				break;
			}
		}
		if(n == 23 && m > 32)
			ans = 60 - m;

		System.out.println(ans);

		in.close();
	}
}


import java.util.Scanner;

public class CodeForces {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		if (n < 0) {
			n = -n;
		}

		int next = 1;

		while (n > 0 || n % 2 == -1) {
			n -= next;
			++next;
		}

		System.out.println(next - 1);
		in.close();
	}
}


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

public class Main implements Runnable {

    long m = (int)1e9+7;
    PrintWriter w;
    ArrayList<Integer> prime;
    boolean is_prime[];
    InputReader c;
    public void run() {
        c = new InputReader(System.in);
        w = new PrintWriter(System.out);

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

        int[] seq = scanArrayI(n);
        int[] fin = scanArrayI(m);

        for(int i = 0; i < n; i++){
            for(int j = 0; j < m; j++){
                if(seq[i] == fin[j]){
                    w.print(fin[j] + " ");
                }
            }
        }
        w.close();
    }

    private String removeSpaces(int[] a){

        StringBuffer s = new StringBuffer();

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

            s.append(a[i] + "");

        }
        return s.toString();
    }

    static long gcd(long a, long b) {
        if (b == 0)
            return a;
        return gcd(b, a % b);
    }
    void sieve(int n) {
        is_prime = new boolean[n+10];
        prime = new ArrayList<>();
        for(int i=2;i<=n;i++)
            is_prime[i] = true;

        for (int i = 2; i <= n; ++i) {
            if (is_prime[i]) prime.add(i);
            for (int j = 0; j < prime.size () && i * prime.get(j) < n; ++j) {
                is_prime[i * prime.get(j)] = false;
                if (i % prime.get(j) == 0) break;
            }
        }
    }
    public static void sortbyColumn(int arr[][], int col){
        Arrays.sort(arr, new Comparator<int[]>()
        {
            public int compare(int[] o1, int[] o2){
                return(Integer.valueOf(o1[col]).compareTo(o2[col]));
            }
        });

    }
    public static class DJSet {
        public int[] upper;

        public DJSet(int n) {
            upper = new int[n];
            Arrays.fill(upper, -1);
        }

        public int root(int x) {
            return upper[x] < 0 ? x : (upper[x] = root(upper[x]));
        }

        public boolean equiv(int x, int y) {
            return root(x) == root(y);
        }

        public boolean union(int x, int y) {
            x = root(x);
            y = root(y);
            if (x != y) {
                if (upper[y] < upper[x]) {
                    int d = x;
                    x = y;
                    y = d;
                }
                upper[x] += upper[y];
                upper[y] = x;
            }
            return x == y;
        }
    }
    public static int[] radixSort(int[] f)    {
        int[] to = new int[f.length];
        {
            int[] b = new int[65537];
            for(int i = 0;i < f.length;i++)b[1+(f[i]&0xffff)]++;
            for(int i = 1;i <= 65536;i++)b[i]+=b[i-1];
            for(int i = 0;i < f.length;i++)to[b[f[i]&0xffff]++] = f[i];
            int[] d = f; f = to;to = d;
        }
        {
            int[] b = new int[65537];
            for(int i = 0;i < f.length;i++)b[1+(f[i]>>>16)]++;
            for(int i = 1;i <= 65536;i++)b[i]+=b[i-1];
            for(int i = 0;i < f.length;i++)to[b[f[i]>>>16]++] = f[i];
            int[] d = f; f = to;to = d;
        }
        return f;
    }
    public void printArray(int[] a){
        for(int i=0;i<a.length;i++)
            w.print(a[i]+" ");
        w.println();
    }
    public int[] scanArrayI(int n){
        int a[] = new int[n];
        for(int i=0;i<n;i++)
            a[i] = c.nextInt();
        return a;
    }
    public long[] scanArrayL(int n){
        long a[] = new long[n];
        for(int i=0;i<n;i++)
            a[i] = c.nextLong();
        return a;
    }
    public void printArray(long[] a){
        for(int i=0;i<a.length;i++)
            w.print(a[i]+" ");
        w.println();
    }
    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;
        private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

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

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

            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                }
                catch (IOException e) {
                    throw new InputMismatchException();
                }

                if(numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            }
            catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
        public int nextInt() {
            int c = read();

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

            int sgn = 1;

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

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

            return res * sgn;
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;

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

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

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

            return res.toString();
        }

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

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

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }
    public static void main(String args[]) throws Exception {
        new Thread(null, new Main(),"Main",1<<26).start();
    }
}


import java.io.*;
import java.util.*;
import java.math.*;
import static java.lang.Math.*;
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.Double.parseDouble;
import static java.lang.String.*;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder out = new StringBuilder();
        StringTokenizer tk;

        String s = in.readLine();
        int x=101,y=101;
        int [][] v = new int[205][205];
        v[x][y] = 1;

        for(int i=0; i<s.length(); i++) {
            if(s.charAt(i)=='L') y--;
            else if(s.charAt(i)=='R') y++;
            else if(s.charAt(i)=='U') x++;
            else x--;

            if(v[x][y]!=0 || (v[x][y+1]!=0 && s.charAt(i)!='L') || (v[x][y-1]!=0 && s.charAt(i)!='R') || (v[x+1][y]!=0 && s.charAt(i)!='D') || (v[x-1][y]!=0 && s.charAt(i)!='U')) {
                //System.out.println(i+" "+v[x-1][y]+" "+x+" , "+y);
                System.out.println("BUG");
                return;
            }
            v[x][y] = i+2;
        }

        if(((x+1==101 && y==101) || (x-1==101 && y==101) || (x==101 && y+1==101) || (x==101 && y-1==101)) && s.length()>1) System.out.println("BUG");
        else System.out.println("OK");
    }

}


import java.util.*;

public class Main {

	static int[] dp=new int[20000];
	static int[][] grid=new int[4][4];
	static int same(int pos, int dir)
	{
		int cross=0, circle=0;
		if (dir==1)
		{
			for (int i=0; i<3; i++)
				if (grid[pos][i]==0)
					return 0;
				else if (grid[pos][i]==1)
					cross++;
				else
					circle++;
			if (cross==3)
				return 1;
			if (circle==3)
				return 2;
			return 0;
		}
		else if (dir==2)
		{
			for (int i=0; i<3; i++)
				if (grid[i][pos]==0)
					return 0;
				else if (grid[i][pos]==1)
					cross++;
				else
					circle++;
			if (cross==3)
				return 1;
			if (circle==3)
				return 2;
			return 0;
		}
		else if (dir==3)
		{
			for (int i=0; i<3; i++)
				if (grid[i][i]==0)
					return 0;
				else if (grid[i][i]==1)
					cross++;
				else
					circle++;
			if (cross==3)
				return 1;
			if (circle==3)
				return 2;
			return 0;
		}
		else if (dir==4)
		{
			for (int i=0; i<3; i++)
				if (grid[i][2-i]==0)
					return 0;
				else if (grid[i][2-i]==1)
					cross++;
				else
					circle++;
			if (cross==3)
				return 1;
			if (circle==3)
				return 2;
			return 0;
		}
		return 0;
	}
	static int win()
	{
		for (int i=0; i<3; i++)
		{
			int temp=same(i, 1);
			if (temp>0)
				return temp;
			temp=same(i, 2);
			if (temp>0)
				return temp;
		}
		int temp=same(0, 3);
		if (temp>0)
			return temp;
		temp=same(0, 4);
		if (temp>0)
			return temp;
		return 0;
	}

	static void fill(int cnt, int next)
	{
		if (dp[cnt]>0)
			return;
		int temp=win();
		if (temp>0)
		{
			dp[cnt]=temp+2;
			return;
		}
		else
			dp[cnt]=next;
		/*
		if (cnt==7)
			System.out.println(cnt+" "+next);
		*/
		int flag=1;
		int tag=0;
		for (int i=0; i<3; i++)
			for (int j=0; j<3; j++)
			{
				if (grid[i][j]==0)
				{
					grid[i][j]=next;
					fill(cnt+flag*next, 3-next);
					grid[i][j]=0;
					tag=1;
				}
				flag*=3;
			}
		if (tag==0)
			dp[cnt]=5;

	}

	public static void main(String[] args)
	{

		Scanner cin=new Scanner(System.in);
		String temp;

		for (int i=0; i<3; i++)
			for (int j=0; j<3; j++)
				grid[i][j]=0;
		fill(0, 1);

		int flag=1, cnt=0;
		for (int i=0; i<3; i++)
		{
			temp=cin.next();
			for (int j=0; j<3; j++)
			{
				if (temp.charAt(j)=='X')
					cnt+=flag;
				else if (temp.charAt(j)=='0')
					cnt+=2*flag;
				flag*=3;
			}
		}
	//	System.out.println(cnt);
		if (dp[cnt]==0)
			System.out.println("illegal");
		else if (dp[cnt]==1)
			System.out.println("first");
		else if (dp[cnt]==2)
			System.out.println("second");
		else if (dp[cnt]==3)
			System.out.println("the first player won");
		else if (dp[cnt]==4)
			System.out.println("the second player won");
		else if (dp[cnt]==5)
			System.out.println("draw");
	}

}


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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
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);
        CGourmetCat solver = new CGourmetCat();
        solver.solve(1, in, out);
        out.close();
    }

    static class CGourmetCat {
        public void solve(int testNumber, InputReader sc, OutputWriter out) {
            long aa = sc.nextLong();
            long bb = sc.nextLong();
            long cc = sc.nextLong();
            long ans = 0;
            for (int i = 1; i <= 7; i++) {
                long x = aa / 3;
                long y = bb / 2;
                long z = cc / 2;
                long min = Math.min(Math.min(x, y), z);
                long div = min;
                long a = aa - div * 3;
                long b = bb - div * 2;
                long c = cc - div * 2;
                long day = (long) i;
                long spent = div * 7;
                long food = a + b + c;
                while (food > 0) {
                    long curr = day % 7;
                    if (curr == 0)
                        curr = 7;
                    if (curr == 1 || curr == 2 || curr == 5) {
                        if (a == 0)
                            break;
                        a--;
                    } else if (curr == 3 || curr == 7) {
                        if (b == 0)
                            break;
                        b--;
                    } else {
                        if (c == 0)
                            break;
                        c--;
                    }
                    day++;
                    spent++;
                    food--;
                }
                if (spent > ans)
                    ans = spent;
            }
            out.println(ans);
        }

    }

    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 close() {
            writer.close();
        }

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

    }

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

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

		int sum = 0;
		boolean flag1 = true;
		boolean flag2 = true;
		boolean flag3 = true;
		boolean flag4 = true;
		boolean flag5 = true;
		boolean flag6 = true;
		boolean flag7 = true;
		boolean flag8 = true;

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

			String s = sc.nextLine();
			boolean flag = true;
			for (int k = 0; k < 8 && flag == true; k++) {
				if (s.charAt(k) != 'B') {
					flag = false;
				}
				if (s.charAt(k) == 'B' && k == 7) {
					sum++;

				}

			}

			for (int j = 1; j <= 8; j++) {
				if (s.charAt((j - 1)) != 'B') {
					if (j == 1) {
						flag1 = false;
					} else if (j == 2) {
						flag2 = false;
					} else if (j == 3) {
						flag3 = false;
					} else if (j == 4) {
						flag4 = false;
					} else if (j == 5) {
						flag5 = false;
					} else if (j == 6) {
						flag6 = false;
					} else if (j == 7) {
						flag7 = false;
					} else if (j == 8) {
						flag8 = false;
					}
				}

			}

		}
		if (flag1 == true) {
			sum++;
		}
		if (flag2 == true) {
			sum++;
		}
		if (flag3 == true) {
			sum++;
		}
		if (flag4 == true) {
			sum++;
		}

		if (flag5 == true) {
			sum++;
		}
		if (flag6 == true) {
			sum++;
		}
		if (flag7 == true) {
			sum++;
		}
		if (flag8 == true) {
			sum++;
		}
		if (sum == 16) {
			System.out.println(8);
		} else {
			System.out.println(sum);
		}

	}

}


import java.util.*;
import java.lang.*;
public class Main
{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
	    String s = sc.next();
	    int n = s.length();
	    int c1 = 0;
	    int c2 = 0;
	    char c[] = s.toCharArray();
	    for(int i=0;i<n-1;i++){
	        if(c[i]=='V'&&c[i+1]=='K'){
	            c1++;
	            c[i]='a';
	            c[i+1]='b';
	            i++;
	        }
	    }
	    for(int i=0;i<n-1;i++){
	        if((c[i]=='V'&&c[i+1]=='V')||(c[i]=='K'&&c[i+1]=='K')){
	            c2++;
	            break;
	        }
	    }
	    if(c2==0) System.out.println(c1);
	    else System.out.println(c1+1);
	}
}


import java.util.Scanner;

public class Chess {
	static int[] shift = { -1, 2, 1, 2, -2, 1, 2, 1, -2, -1, 2, -1, 1, -2, -1,
			-2 };

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		boolean[][] board = new boolean[8][8];
		String rook = sc.next();
		int row = rook.charAt(0) - 'a';
		int col = rook.charAt(1) - '0' - 1;
		for (int i = 0; i < 8; i++)
			board[row][i] = true;
		for (int i = 0; i < 8; i++)
			board[i][col] = true;

		String knight = sc.next();
		int row1 = knight.charAt(0) - 'a';
		int col1 = knight.charAt(1) - '0' - 1;
		board[row1][col1] = true;
		for (int i = 0; i < shift.length - 1; i += 2) {
			int dx = row1 + shift[i];
			int dy = col1 + shift[i + 1];
			if (dx >= 0 && dx < 8 && dy < 8 && dy >= 0)
				board[dx][dy] = true;
		}
		int counter = 0;
		for (int i = 0; i < 8; i++)
			for (int j = 0; j < 8; j++)
				if (!board[i][j] && check(board, i, j, row, col))
					counter++;

		System.out.println(counter);

	}

	private static boolean check(boolean[][] board, int x, int y, int row,
			int col) {
		for (int i = 0; i < shift.length - 1; i += 2) {
			int dx = x + shift[i];
			int dy = y + shift[i + 1];
			if (dx == row && dy == col)
				return false;
		}
		return true;
	}
}


import java.io.*;
import java.util.*;
import java.text.*;
import java.lang.*;
import java.util.regex.*;
public class Myclass {
	static long  a[]=new long  [10000];
	static long power(long n,long m)
	{
		long ans=1,x=2;
		while(n>0)
		{
			if(n%2==1)
			{
				ans=ans*x;
				n--;
			}
			if(x>m && n>0)
				return -1;
			//System.out.println(ans);
			x=x*x;
			n/=2;
		}
		//System.out.println(ans);
		return m%ans;
	}
	public static void main(String[] args) {

		InputReader in = new InputReader(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		long n=in.nextLong();
		long m=in.nextLong();
		if(m/2<n)
		{
			pw.print(m);
		}
		else
		{
			long ans=power(n,m);
			if(ans==-1)
				pw.print(m);
			else
				pw.println(ans);
		}
		pw.flush();
		pw.close();

	}
		private static pair r(long l) {
		// TODO Auto-generated method stub
		return null;
	}
		static class InputReader
		{
		private final InputStream stream;
		private final byte[] buf = new byte[8192];
		private int curChar, snumChars;
		private SpaceCharFilter filter;

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

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

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

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

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

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

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

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

		public interface SpaceCharFilter
	    {
			public boolean isSpaceChar(int ch);
		}
	}
		public static long mod = 1000000007;
		public static int d;
		public static int p;
		public static int q;

		public static int[] suffle(int[] a,Random gen)
		{
			int n = a.length;
			for(int i=0;i<n;i++)
			{
				int ind = gen.nextInt(n-i)+i;
				int temp = a[ind];
				a[ind] = a[i];
				a[i] = temp;
			}
			return a;
		}

		public static void swap(int a, int b){
			int temp = a;
			a = b;
			b = temp;
		}

		public static HashSet<Integer> primeFactorization(int n)
		{
			HashSet<Integer> a =new HashSet<Integer>();
			for(int i=2;i*i<=n;i++)
			{
				while(n%i==0)
				{
					a.add(i);
					n/=i;
				}
			}
			if(n!=1)
				a.add(n);
			return a;
		}

		public static void sieve(boolean[] isPrime,int n)
		{
			for(int i=1;i<n;i++)
				isPrime[i] = true;

			isPrime[0] = false;
			isPrime[1] = false;

			for(int i=2;i*i<n;i++)
			{
				if(isPrime[i] == true)
				{
					for(int j=(2*i);j<n;j+=i)
						isPrime[j] = false;
				}
			}
		}

		public static int GCD(int a,int b)
		{
			if(b==0)
				return a;
			else
				return GCD(b,a%b);
		}

		public static long GCD(long a,long b)
		{
			if(b==0)
				return a;
			else
				return GCD(b,a%b);
		}

		public static void extendedEuclid(int A,int B)
		{
			if(B==0)
			{
				d = A;
				p = 1 ;
				q = 0;
			}
			else
			{
				extendedEuclid(B, A%B);
				int temp = p;
				p = q;
				q = temp - (A/B)*q;
			}
		}

		public static long LCM(long a,long b)
		{
			return (a*b)/GCD(a,b);
		}

		public static int LCM(int a,int b)
		{
			return (a*b)/GCD(a,b);
		}

		public static int binaryExponentiation(int x,int n)
		{
		    int result=1;
		    while(n>0)
		    {
		        if(n % 2 ==1)
		            result=result * x;
		        x=x*x;
		        n=n/2;
		    }
		    return result;
		}

		public static long binaryExponentiation(long x,long n)
		{
		    long result=1;
		    while(n>0)
		    {
		        if(n % 2 ==1)
		            result=result * x;
		        x=x*x;
		        n=n/2;
		    }
		    return result;
		}

		public static int modularExponentiation(int x,int n,int M)
		{
		    int result=1;
		    while(n>0)
		    {
		        if(n % 2 ==1)
		            result=(result * x)%M;
		        x=(x*x)%M;
		        n=n/2;
		    }
		    return result;
		}

		public static long modularExponentiation(long x,long n,long M)
		{
		    long result=1;
		    while(n>0)
		    {
		        if(n % 2 ==1)
		            result=(result * x)%M;
		        x=(x*x)%M;
		        n=n/2;
		    }
		    return result;
		}

		public static int modInverse(int A,int M)
		{
		    return modularExponentiation(A,M-2,M);
		}

		public static long modInverse(long A,long M)
		{
		    return modularExponentiation(A,M-2,M);
		}

		public static boolean isPrime(int n)
		{

		    if (n <= 1)  return false;
		    if (n <= 3)  return true;

		    if (n%2 == 0 || n%3 == 0)
		    	return false;

		    for (int i=5; i*i<=n; i=i+6)
		    {
		        if (n%i == 0 || n%(i+2) == 0)
		           return false;
		    }

		    return true;
		}

		static class pair implements Comparable<pair>
		{
			Long x, y;
			pair(long x,long y)
			{
				this.x=x;
				this.y=y;
			}

			public int compareTo(pair o) {
				int result = x.compareTo(o.x);
				if(result==0)
					result = y.compareTo(o.y);

				return result;
			}

			public String toString()
			{
				return x+" "+y;
			}

			public boolean equals(Object o)
			{
				if (o instanceof pair)
			    {
					pair p = (pair)o;
					return p.x == x && p.y == y ;
				}
				return false;
			}

			public int hashCode()
			{
				return new Long(x).hashCode()*31 + new Long(y).hashCode();
			}
		}
}


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

public class Main {
	static class Reader
    {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public Reader()
        {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Reader(String file_name) throws IOException
        {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public 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 int nextInt() 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 long nextLong() 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 double nextDouble() 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 void fillBuffer() throws IOException
        {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

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

        public void close() throws IOException
        {
            if (din == null)
                return;
            din.close();
        }
    }

	static class time implements Comparable<time>{
		int l,r;
		time(int x,int y){
			l=x;
			r=y;
		}
		@Override
		public int compareTo(time ob){
			int diff = this.l-ob.l;
			if(diff!=0)
				return diff;
			return this.r-ob.r;
		}
	}
	public static void main(String args[])throws IOException{
		Reader in=new Reader();
		long n=in.nextLong();
		long m=in.nextLong();
		if(m>=n){
			System.out.println(n);
			System.exit(0);
		}
		n -= m;
		long l = 0, r = (long)2e9;
		while (l < r) {
			long med = (l + r) / 2;
			long val = med * (med+1) / 2;
			if (val >= n) {
				r = med;
			} else {
				l = med+1;
			}
		}
		System.out.println(l+m);
	}
}