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

public class Main
{
    static long mod=1000000007;
    static long p=(long)1e10;
    public static void main(String[] args) throws Exception
    {
    	FastReader in=new FastReader();
    	PrintWriter pw=new PrintWriter(System.out);
    	int n=in.nextInt();
    	long sum=0,max=0;
    	for(int i=0;i<n;i++)
    	{
    		long temp=in.nextInt();
    		sum+=temp;
    		max=Math.max(temp,max);
    	}
    	long ans=n*max-sum;
    	while(ans<=sum)
    	{
    		max++;
    		ans=n*max-sum;
    	}
    	pw.println(max);
    	pw.flush();
    }

}

class pair<A,B>
{
    A f;
    B s;

    public pair(A a,B b)
    {
        f=a;
        s=b;
    }
}

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.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * CodeForces : 338
 *
 * @author vinaysaini E. Hexagons
 */
public class cf338e {

	static int dx[] = { 1, -1, -2, -1, 1, 2 };
	static int dy[] = { 2, 2, 0, -2, -2, 0 };

	public static void main(String[] args) {
		long x = 0, y = 0;

		long n = in.nextLong();
		long ringNumber = getRing(n);
		long stepsUpTo = 3 * ringNumber * ringNumber + 3 * ringNumber;
		x = 2 * ringNumber;
		long remainingSteps = n - stepsUpTo;
		if (remainingSteps > 0) {
			x = x + dx[0];
			y = y + dy[0];
			remainingSteps--;
		}
		if (remainingSteps >= ringNumber) {
			x += dx[1] * ringNumber;
			y += dy[1] * ringNumber;
			remainingSteps -= ringNumber;
		} else {
			x += dx[1] * remainingSteps;
			y += dy[1] * remainingSteps;
			remainingSteps -= remainingSteps;
		}
		if (remainingSteps >= ringNumber+1) {
			x += dx[2] * (ringNumber+1);
			y += dy[2] * (ringNumber+1);
			remainingSteps -= ringNumber+1;
		} else {
			x += dx[2] * remainingSteps;
			y += dy[2] * remainingSteps;
			remainingSteps -= remainingSteps;
		}
		if (remainingSteps >= ringNumber+1) {
			x += dx[3] * (ringNumber+1);
			y += dy[3] * (ringNumber+1);
			remainingSteps -= ringNumber+1;
		} else {
			x += dx[3] * remainingSteps;
			y += dy[3] * remainingSteps;
			remainingSteps -= remainingSteps;
		}
		if (remainingSteps >= ringNumber+1) {
			x += dx[4] * (ringNumber+1);
			y += dy[4] * (ringNumber+1);
			remainingSteps -= ringNumber+1;
		} else {
			x += dx[4] * remainingSteps;
			y += dy[4] * remainingSteps;
			remainingSteps -= remainingSteps;
		}
		if (remainingSteps >= ringNumber+1) {
			x += dx[5] * (ringNumber+1);
			y += dy[5] * (ringNumber+1);
			remainingSteps -= ringNumber+1;
		} else {
			x += dx[5] * remainingSteps;
			y += dy[5] * remainingSteps;
			remainingSteps -= remainingSteps;
		}
		if (remainingSteps >= ringNumber) {
			x += dx[0] * ringNumber;
			y += dy[0] * ringNumber;
			remainingSteps -= ringNumber;
		} else {
			x += dx[0] * remainingSteps;
			y += dy[0] * remainingSteps;
			remainingSteps -= remainingSteps;
		}

		out.println(x + " " + y);
		out.close();
	}

	static long getRing(long n) {
		long l = 0;
		long r = (long) 1e9;
		while (l < r) {
			long m = (l + r) / 2;
			long sum = 3 * m * m + 3 * m;
			if (n < sum) {
				r = m;
			} else
				l = m + 1;
		}
		return l - 1;
	}

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

	public static class FastScanner {
		BufferedReader br;
		StringTokenizer st;

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

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

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

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

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

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	} // --fast i/o ends here----//

}


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

public class MAin {

	public static void main(String[] args) {

		BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(System.in));

		try {

			int n=Integer.parseInt(bufferedReader.readLine());

			int[] num=new int[n];

			int minI=-90;
			int maxI=-90;
			String[] input=bufferedReader.readLine().split(" ");
			int min=Integer.MAX_VALUE;
			int max=Integer.MIN_VALUE;
			for(int i=0;i<n;i++){

				int val=Integer.parseInt(input[i]);

				if (val>max) {
					max=val;
					maxI=i;
				}

				if (val<min) {
					min=val;
					minI=i;
				}

			}

			int a,b,c,d;

			a=minI-0;
			b=n-minI-1;

			c=maxI-0;
			d=n-maxI-1;

			int max1=Math.max(a, b);

			int max2=Math.max(c, d);

			int ans=Math.max(max1, max2);

			System.out.println(ans);

		} catch (Exception e) {
			// TODO: handle exception
		}

	}

}


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

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

class Solver {
	PrintWriter out;
	FastReader cd;
	@SuppressWarnings("unused")
	public static final int INF = 0x3f3f3f3f;
	@SuppressWarnings("unused")
	public static final double MINI = 1e-6, ATOM = 1e-8;

	Solver() {
		out = new PrintWriter(System.out, true);
		cd = new FastReader();
	}

	Solver solve() {
		String[] time1 = cd.next().split(":"), time2 = cd.next().split(":");
		int real1 = Integer.parseInt(time1[0])*60 + Integer.parseInt(time1[1]), real2 = Integer.parseInt(time2[0]) * 60 + Integer.parseInt(time2[1]);
		int res = (real1 + real2) / 2;
		out.printf("%02d:%02d", res / 60, res % 60);
		return this;
	}

	void end() {
		out.close();
		cd.close();
	}

	@SuppressWarnings("unused")
	class FastReader {
		private BufferedReader in;
		private StringTokenizer tokenizer;

		FastReader() {
			in = new BufferedReader(new InputStreamReader(System.in), 23333);
			tokenizer = null;
		}

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

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

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

		int[] nextInts(int len) {
			int[] a = new int[len];
			for (int i = 0; i < a.length; i++) {
				a[i] = cd.nextInt();
			}
			return a;
		}

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

		void close() {
			try {
				in.close();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
	}
}


import java.util.*;
import java.util.StringTokenizer;
import java.io.*;
public class Main {
    static int []arr;
    static int [][]dp;
    static String s;
    static ArrayList<Integer>[]G;

    public static int solve(int idx,int rem)
    {
        if (rem<=0) return 0;
        if (dp[idx][rem]!=-1) return dp[idx][rem];
        dp[idx][rem]=(int)1e6;
        for (int i=1;i<=3;++i)
        {
            if (i==1&&s.charAt(idx-1)=='R') continue;
            if (i==2&&s.charAt(idx-1)=='G') continue;
            if (i==3&&s.charAt(idx-1)=='B') continue;
            for (int u:G[i])
                if (arr[u]>arr[idx])
                    dp[idx][rem]=Math.min(dp[idx][rem],(solve(u, rem - arr[u])+Math.abs(u-idx)));
        }
        return dp[idx][rem];
    }

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

        int n=sc.nextInt();
        int pos=sc.nextInt();
        int k=sc.nextInt();
        G = new ArrayList[5];
        for (int i=0;i<5;++i) G[i] = new ArrayList();
        arr =new int [n+5];
        dp=new int [n+5][k+5];
        for (int i=0;i<=n+1;++i)
            for (int j=0;j<=k+1;++j)
                dp[i][j]=-1;

        for (int i=1;i<=n;++i) arr[i]=sc.nextInt();
        s=sc.nextLine();
        for (int i=0;i<n;++i)
        {
            char ch=s.charAt(i);
            if ( ch == 'R')
                G[1].add(i + 1);
            else if (ch == 'G')
                G[2].add(i + 1);
            else G[3].add(i + 1);
        }

        int cnt=(int)1e6;
        for (int i=1;i<=n;++i)
            cnt=Math.min(cnt,solve(i,k-arr[i])+Math.abs(i-pos));

        out.println((cnt>=(int)1e6)?-1:cnt);
        out.close();
    }
    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();}
    }
}


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

// PROBLEM : Can teleport between cells corresponding to the same string
public class B {
    static int n;
    static char[][] G;
    public static void main(String[] args) throws Exception {
        Scanner in = new Scanner(System.in);
        n = in.nextInt();
        G = new char[n][n];
        F = new HashMap<Long, Integer>();
        for(int r=0; r<n; r++) {
            G[r] = in.next().toCharArray();
        }
        int ans = ch_to_val(G[0][0],true)-f(0,new boolean[]{true},false);
        if(ans > 0) System.out.println("FIRST");
        if(ans < 0) System.out.println("SECOND");
        if(ans == 0) System.out.println("DRAW");
    }

    static int ch_to_val(char ch, boolean first) {
        if(ch=='a') return first ? 1 : -1;
        if(ch=='b') return first ? -1 : 1;
        return 0;
    }

    static long hash(int sum, boolean[] R) {
        long hash = sum;
        for(int i=0; i<R.length; i++)
            hash = hash*2 + (R[i] ? 1 : 0);
        return hash;
    }

    // Returns max score for person to play; given square has already been claimed
    static HashMap<Long,Integer> F;
    static int f(int sum, boolean[] R, boolean first) {
        long key = hash(sum, R);
        if(F.containsKey(key)) return F.get(key);
        if(sum == 2*(n-1)) return 0;

        int ans = -1000;
        int ns = sum+1;
        Character[] CH = new Character[ns+1];
        for(int r=0; r<=sum+1; r++) {
            boolean can_see = (r<R.length && R[r]) || (r-1>=0 && R[r-1]);
            if(!can_see) continue;
            int c = ns-r;
            if(c<0 || c>=n || r<0 || r>=n) continue;
            CH[r] = G[r][c];
        }

        for(int r=0; r<=sum+1; r++) {
            if(CH[r] != null) {
                char ch = CH[r];
                boolean[] NR = new boolean[ns+1];
                for(int rr=0; rr<=sum+1; rr++)
                    if(CH[rr]!=null && CH[rr] == ch) {
                        NR[rr] = true;
                        CH[rr] = null;
                    }
                ans = Math.max(ans, ch_to_val(ch,first) - f(ns, NR, !first));
            }
        }
        F.put(key, ans);
        return ans;
    }
}


import java.util.Scanner;

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

		int n = r.nextInt();
		int w = r.nextInt();
		int a = r.nextInt()-1;
		int b = r.nextInt()-1;

		int am = a%w;
		int bm = b%w;

		int res = 3;

		if(w == 1)res = 1;
		else if(a == b)res = 1;
		else if(a/w == b/w)res = 1;
		else if(am == 0 && bm == w-1)res = 1;
		else if(am == 0 && b == n-1)res = 1;
		else if(b/w - a/w == 1)res = 2;
		else if(am == 0)res = 2;
		else if(bm == w-1)res = 2;
		else if(b == n-1)res = 2;
		else if(am - bm == 1)res = 2;
		else res = 3;

		System.out.println(Math.max(1, res));
	}
}


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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author emotionalBlind
 */
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();
    }
}

class TaskC {

    int getN(int x) {
        if (x == 1) return 1;
        if (x == 2) return 3;
        if (x == 3) return 5;
        if (x == 4) return 3;
        if (x == 5) return 3;
        if (x <= 13) return 5;
        for (int i = 7; i <= 100; i += 2) {
            int v = i * i + 1;
            v /= 2;
            if (x <= v) return i;
        }
        return 101;
    }

    public void solve(int testNumber, InputReader in, OutputWriter out) {
        int x = in.readInt();
        out.printLine(getN(x));
    }
}

class InputReader {

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

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

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

    public int readInt() {
        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 static boolean isSpaceChar(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    }

class OutputWriter {
    private final PrintWriter writer;

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

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

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

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

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

}


import java.util.Scanner;

public class B {
	Scanner sc = new Scanner(System.in);

	void run() {
		int m = sc.nextInt();
		int zero = 0;
		for (int i = 5; zero < m; i += 5) {
			int tmp = i;
			while (tmp > 0 && tmp % 5 == 0) {
				zero ++;
				tmp /= 5;
			}
			if (zero == m) {
				StringBuilder out = new StringBuilder();
				out.append("5\n");
				for (int j = i; j <= i + 4; j++) out.append(j + " ");
				System.out.println(out);
				return;
			}
		}
		System.out.println(0);
	}

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


import java.util.*;
import java.io.*;
import java.io.FileWriter;
import java.math.BigInteger;
import java.math.BigDecimal;
// Solution

public class Main
{
  public static void main (String[] argv)
  {
	  new Main();
  }

  boolean test = false;
  final int[][] dirs8 = {{0,1}, {0,-1}, {-1,0}, {1,0}, {1,1},{1,-1},{-1,1},{-1,-1}};
  final int[][] dirs4 = {{0,1}, {0,-1}, {-1,0}, {1,0}};
  final int MOD = 1000000007;  //998244353;

  final int WALL = -1;
  final int EMPTY = -2;
  final int VISITED = 1;
  final int FULL = 2;

  final int START = 1;
  final int END = 0;

  int[] fac;
  int[] ifac;
  int[] rfac;

  int[] pow2;

  int[] mobius;
  int[] sieve;
  int[][] factors;

  final int UNVISITED = -2;

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

    //FastReader in = new FastReader(new BufferedReader(new FileReader("Main.in")));

    //int nt = in.nextInt();
    int nt = 1;
    StringBuilder sb = new StringBuilder();

    for (int it = 0; it < nt; it++)
    {
       long n = in.nextLong();
       long k = in.nextLong();

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

//System.out.println("n = " + n + " k = " + k);
       //binary search on odd numbers
       long lo = 1, hi = n / 2;

       while (lo <= hi)
       {

           long mid = (hi + lo) / 2;
           long val = mid * 2 - 1;
//System.out.println("lo = " + lo + " hi = " + hi + ", mid = " + mid + ", val = " + val);
           if (cnt(val, n) >= k) {
               //System.out.println("cnt >= 100");
               lo = mid + 1;
           }
           else {
               //System.out.println("cnt < 100");
               hi = mid - 1;
           }
       }
       long cand = hi * 2 - 1;
       if (cnt(cand, n) < k) cand = 0;

       lo = 1;
       hi = n / 2;

       while (lo <= hi)
       {
           long mid = (hi + lo) / 2;
           long val = mid * 2;
           if (cnt(val, n) >= k)
               lo = mid + 1;
           else hi = mid - 1;
       }

       cand = Math.max(cand, hi * 2);
       System.out.println(cand);
    }

    System.out.print(sb);

  }

  private long cnt(long v, long n)
  {
//System.out.println("cnting " + v + " " + n);
      if (v > n) return 0;

      long cnt = 0;
      if (v % 2 == 1) {
          long segSize = 1;
          long start = v;
          while(start <= n){
              long end = Math.min(n, start + segSize - 1);
              cnt += end - start + 1;

              segSize *= 2;
              start *= 2;
          }

      }else {

          long segSize = 2;
          long start = v;
          while(start <= n){
              long end = Math.min(n, start + segSize - 1);
              cnt += end - start + 1;

              segSize *= 2;
              start *= 2;
          }

      }
//System.out.println("cnt = " + cnt);
      return cnt;
  }

  class Node implements Comparable<Node>{
      int lo, hi;
      public Node(int lo, int hi)
      {
          this.lo = lo;
          this.hi = hi;
      }

      @Override
      public int compareTo(Node o){
          if (lo != o.lo) return lo - o.lo;
          return hi - o.hi;
      }
  }

  private long[][] matIdentity(int n)
  {
      long[][] a = new long[n][n];
      for (int i = 0; i < n; i++)
          a[i][i] = 1;
      return a;
  }
  private long[][] matPow(long[][] mat0, long p)
  {
      int n = mat0.length;
      long[][] ans = matIdentity(n);
      long[][] mat = matCopy(mat0);
      while (p > 0)
      {
          if (p % 2 == 1){
              ans = matMul(ans, mat);
          }

          p /= 2;
          mat = matMul(mat, mat);
      }
      return ans;
  }

  private long[][] matCopy(long[][] a)
  {
      int n = a.length;
      long[][] b = new long[n][n];
      for (int i = 0; i < n; i++)
          for (int j = 0; j < n; j++)
              b[i][j] = a[i][j];
      return b;
  }
  private long[][] matMul(long[][] a, long[][] b)
  {
      int n = a.length;

      long[][] c = new long[n][n];
      for (int i = 0; i < n; i++)
      {
          for (int j = 0; j < n; j++)
          {
              for (int k = 0; k < n; k++)
                  c[i][j] = (c[i][j] + a[i][k] * b[k][j]) % MOD;
          }
      }

      return c;
  }

  private long[] matMul(long[][] a, long[] b)
  {
      int n = a.length;

      long[] c = new long[n];
      for (int i = 0; i < n; i++)
      {
          for (int j = 0; j < n; j++)
              c[i] = (c[i] + a[i][j] * b[j]) % MOD;
      }

      return c;
  }

  class Mark implements Comparable<Mark> {
      int type, h;
      long x;
      public Mark(int h, long x, int type)
      {
         this.h = h;
         this.x = x;
         this.type = type;
      }

      @Override
      public int compareTo(Mark o)
      {
          if (this.x == o.x) return type - o.type; // let end comes before start
          return Long.compare(x, o.x);
      }
  }

  private boolean coLinear(int[] p, int[] q, int[] r)
  {
      return 1L * (p[1] - r[1]) * (q[0] - r[0]) == 1L * (q[1] - r[1]) * (p[0] - r[0]);
  }

  private void fill(char[] a, int lo, int c, char letter)
  {
      //System.out.println("fill " + lo + " " + c + " " + letter);
      for (int i = lo; i < lo + c; i++) a[i] = letter;
  }

  private int cntBitOne(String s){
      int c = 0, n = s.length();
      for (int i = 0; i < n; i++)
          if (s.charAt(i) == '1') c++;
      return c;
  }

  class DSU {
      int n;
      int[] par;
      int[] sz;
      int nGroup;

      public DSU(int n)
      {
          this.n = n;
          par = new int[n];
          sz = new int[n];
          for (int i = 0;  i < n; i++){
              par[i] = i;
              sz[i] = 1;
          }
          nGroup = n;
      }

      private boolean add(int p, int q) {
          int rp = find(p);
          int rq = find(q);
          if (rq == rp) return false;

          if (sz[rp] <= sz[rq]) {
              sz[rq] += sz[rp];
              par[rp] = rq;
          }else {
              sz[rp] += sz[rq];
              par[rq] = rp;
          }
          nGroup--;
          return true;
      }

      private int find(int p)
      {
          int r = p;
          while (par[r] != r) r = par[r];

          while (r != p) {
              int t = par[p];
              par[p] = r;
              p = t;
          }
          return r;
      }

  }

  // μ(n) = 1 if n is a square-free positive integer with an even number of prime factors. e.g.  6, 15
  // μ(n) = −1 if n is a square-free positive integer with an odd number of prime factors. e.g.  2, 3, 5, 2*3*5
  // μ(n) = 0 if n has a squared prime factor. e.g : 2*2,  3*3*5
  private void build_pow2_function(int n)
  {
      pow2 = new int[n+1];
       pow2[0] = 1;
       for (int i = 1; i <= n; i++) pow2[i] = (int)(1L * pow2[i-1] * 2 % MOD);
  }

  private void build_fac_function(int n)
  {
      fac = new int[n+1];
      fac[0] = 1;
      for (int i = 1; i <= n; i++)
          fac[i] = (int)(1L * fac[i-1] * i % MOD);
  }

  private void build_ifac_function(int n)
  {
      ifac = new int[n+1];
      ifac[0] = 1;
      for (int i = 1; i <= n; i++)
          ifac[i] = (int)(1L * ifac[i-1] * inv(i) % MOD);
  }

  private void build_sieve_function(int n)
  {
      sieve = new int[n+1];
      for (int i = 2; i <= n; i++)
        sieve[i] = i;
      for (int i = 2; i <= n; i++)
      {
        if (sieve[i] == i){
            for (long j = 1L * i * i; j <= n; j += i)
                sieve[(int)j] = i;
        }
      }
  }

  private void build_mobius_function(int n)
  {
      mobius = new int[n+1];
      sieve = new int[n+1];
      factors = new int[n+1][];
      //for (int i = 1; i <= n; i++)factors[i] = new ArrayList<>();
      for (int i = 2; i <= n; i++)
        sieve[i] = i;
      for (int i = 2; i <= n; i++)
      {
        if (sieve[i] == i){
            mobius[i] = -1;
            for (long j = 1L * i * i; j <= n; j += i)
                sieve[(int)j] = i;
        }
      }

      for (int i = 6; i <= n; i++)
      {
          if (sieve[i] != i) {
              int pre = i / sieve[i];
              if (pre % sieve[i] != 0)
                  mobius[i] = -mobius[pre];
          }
      }
      int[] sz = new int[n+1];
      long tot = 0;
      for (int i = 2; i <= n; i++)
      {
          if (mobius[i] != 0)
          {
              for (int j = i * 2; j <= n; j += i) {
                  sz[j]++;
                  tot++;
              }
          }
      }
      for (int i = 2; i <= n; i++) {
          factors[i] = new int[sz[i]];
          sz[i] = 0;
      }

      for (int i = 2; i <= n; i++)
      {
          if (mobius[i] != 0)
          {
              for (int j = i * 2; j <= n; j += i) {
                  factors[j][sz[j]++] = i;
                  //factors[j].add(i);
              }
          }
      }
      //System.out.println("tot  =  "  + tot);
  }

  private int[] build_z_function(String s)
  {
      int n = s.length();
      int[] zfun = new int[n];

      int l = -1, r = -1;
      for (int i = 1; i < n; i++)
      {
         // Set the start value
         if (i <= r)
            zfun[i] = Math.min(zfun[i-l], r - i + 1);

         while (i + zfun[i] < n && s.charAt(i + zfun[i]) == s.charAt(zfun[i]))
             zfun[i]++;

         if (i + zfun[i] - 1> r){
             l = i;
             r = i + zfun[i] - 1;
         }
      }

      if (test)
      {
          System.out.println("Z-function of " + s);
          for (int i = 0; i < n; i++) System.out.print(zfun[i] + " ");
          System.out.println();
      }
      return zfun;
  }

  class BIT {
      int[] bit;
      int n;

      public BIT(int n){
          this.n = n;
          bit = new int[n+1];
      }

      private int query(int p)
      {
          int sum = 0;
          for (; p > 0; p -= (p & (-p)))
             sum += bit[p];

          return sum;
      }

      private void add(int p, int val)
      {
         //System.out.println("add to BIT " + p);
         for (; p <= n; p += (p & (-p)))
            bit[p] += val;
      }

  }

  private List<Integer> getMinFactor(int sum)
  {
      List<Integer>  factors = new ArrayList<>();

               for (int sz = 2; sz <= sum / sz; sz++){
                   if (sum % sz == 0) {
                       factors.add(sz);
                       factors.add(sum / sz);
                   }
               }
               if (factors.size() == 0)
                   factors.add(sum);

      return factors;
  }

  /* Tree class */
  class Tree {
      int V = 0;
      int root = 0;
      List<Integer>[] nbs;
      int[][] timeRange;
      int[] subTreeSize;
      int t;
      boolean dump = false;

      public Tree(int V, int root)
      {
          if (dump)
              System.out.println("build tree with size = " + V + ", root = " + root);

          this.V = V;
          this.root = root;
          nbs = new List[V];
          subTreeSize = new int[V];
          for (int i = 0; i < V; i++)
              nbs[i] = new ArrayList<>();

      }

      public void doneInput()
      {
          dfsEuler();
      }

      public void addEdge(int p, int q)
      {
          nbs[p].add(q);
          nbs[q].add(p);
      }

      private void dfsEuler()
      {
          timeRange = new int[V][2];
          t = 1;
          dfs(root);
      }

      private void dfs(int node)
      {
          if (dump)
              System.out.println("dfs on node " + node + ", at time " + t);
          timeRange[node][0] = t;

          for (int next : nbs[node]) {
              if (timeRange[next][0] == 0)
              {
                  ++t;
                  dfs(next);
              }
          }
          timeRange[node][1] = t;
          subTreeSize[node] = t - timeRange[node][0] + 1;
      }

      public List<Integer> getNeighbors(int p) {
          return nbs[p];
      }

      public int[] getSubTreeSize(){
          return subTreeSize;
      }

      public int[][] getTimeRange()
      {
          if (dump){
              for (int i = 0; i < V; i++){
                  System.out.println(i + ": " + timeRange[i][0] + " - " + timeRange[i][1]);
              }
          }
          return timeRange;
      }

  }

  /* segment tree */
  class SegTree {
      int[] a;
      int[] tree;
      int[] treeMin;
      int[] treeMax;
      int[] lazy;
      int n;
      boolean dump = false;

      public SegTree(int n)
      {
          if (dump)
              System.out.println("create segTree with size " + n);
          this.n = n;
          treeMin = new int[n*4];
          treeMax = new int[n*4];
          lazy = new int[n*4];
      }

      public SegTree(int n, int[] a) {
          this(n);
          this.a = a;
          buildTree(1, 0, n-1);
      }

      private void buildTree(int node, int lo, int hi)
      {
          if (lo == hi) {
              tree[node] = lo;
              return;
          }

          int m = (lo + hi) / 2;
          buildTree(node * 2, lo, m);
          buildTree(node * 2 + 1, m + 1, hi);
          pushUp(node, lo, hi);
      }

      private void pushUp(int node, int lo, int hi)
      {
          if (lo >= hi) return;

          // note that, if we need to call pushUp on a node, then lazy[node] must be zero.

          //the true value is the value + lazy
          treeMin[node] = Math.min(treeMin[node * 2] + lazy[node * 2], treeMin[node * 2 + 1] + lazy[node * 2 + 1]);
          treeMax[node] = Math.max(treeMax[node * 2] + lazy[node * 2], treeMax[node * 2 + 1] + lazy[node * 2 + 1]);
          // add combine fcn
      }

      private void pushDown(int node, int lo, int hi)
      {
          if (lazy[node] == 0) return;

          int lz = lazy[node];
          lazy[node] = 0;

          treeMin[node] += lz;
          treeMax[node] += lz;

          if (lo == hi) return;

          int mid = (lo + hi) / 2;
          lazy[node * 2] += lz;
          lazy[node * 2 + 1] += lz;
      }

      public int rangeQueryMax(int fr, int to)
      {
          return rangeQueryMax(1, 0, n-1, fr, to);
      }

      public int rangeQueryMax(int node, int lo, int hi, int fr, int to)
      {
          if (lo == fr && hi == to)
              return treeMax[node] + lazy[node];

          int mid = (lo + hi) / 2;
          pushDown(node, lo, hi);

          if (to <= mid) {
              return rangeQueryMax(node * 2, lo, mid, fr, to);
          }else if (fr > mid)
              return rangeQueryMax(node * 2 + 1, mid + 1, hi, fr, to);
          else {
              return Math.max(rangeQueryMax(node * 2, lo, mid, fr, mid),
                              rangeQueryMax(node * 2 + 1, mid + 1, hi, mid + 1, to));
          }
      }

      public int rangeQueryMin(int fr, int to)
      {
          return rangeQueryMin(1, 0, n-1, fr, to);
      }

      public int rangeQueryMin(int node, int lo, int hi, int fr, int to)
      {
          if (lo == fr && hi == to)
              return treeMin[node] + lazy[node];

          int mid = (lo + hi) / 2;
          pushDown(node, lo, hi);

          if (to <= mid) {
              return rangeQueryMin(node * 2, lo, mid, fr, to);
          }else if (fr > mid)
              return rangeQueryMin(node * 2 + 1, mid + 1, hi, fr, to);
          else {
              return Math.min(rangeQueryMin(node * 2, lo, mid, fr, mid),
                              rangeQueryMin(node * 2 + 1, mid + 1, hi, mid + 1, to));
          }
      }

       public void rangeUpdate(int fr, int to, int delta){
           rangeUpdate(1, 0, n-1, fr, to, delta);
       }

      public void rangeUpdate(int node, int lo, int hi, int fr, int to, int delta){
          pushDown(node, lo, hi);
          if (fr == lo && to == hi)
          {
              lazy[node] = delta;
              return;
          }

          int m = (lo + hi) / 2;
          if (to <= m)
              rangeUpdate(node * 2, lo, m, fr, to, delta);
          else if (fr > m)
              rangeUpdate(node * 2 + 1, m + 1, hi, fr, to, delta);
          else  {
              rangeUpdate(node *  2, lo, m, fr, m, delta);
              rangeUpdate(node * 2 + 1, m + 1, hi, m + 1, to, delta);
          }

          // re-set the in-variant
          pushUp(node, lo, hi);
      }

      public int query(int node, int lo, int hi, int fr, int to)
      {
          if (fr == lo && to == hi)
              return tree[node];

          int m = (lo + hi) / 2;
          if (to <= m)
              return  query(node * 2, lo, m, fr, to);
          else if (fr > m)
              return query(node * 2 + 1, m + 1, hi, fr, to);

          int lid = query(node * 2, lo, m, fr, m);
          int rid = query(node * 2 + 1, m + 1, hi, m + 1, to);
          return a[lid] >= a[rid] ? lid : rid;
      }

  }

  private long inv(long v)
  {
      return pow(v, MOD-2);
  }

  private long pow(long v, long p)
  {
      long ans = 1;
      while (p > 0)
      {
          if (p % 2 == 1)
              ans = ans * v % MOD;
          v = v * v % MOD;
          p = p / 2;
      }
      return ans;
  }

  private double dist(double x, double y, double xx, double yy)
  {
      return Math.sqrt((xx - x) * (xx - x) + (yy - y) * (yy - y));
  }

  private int mod_add(int a, int b) {
      int v = a + b;
      if (v >= MOD) v -= MOD;
      return v;
  }

  private long overlap(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) {
      if (x1 > x3) return overlap(x3, y3, x4, y4, x1, y1, x2, y2);

      if (x3 > x2 || y4 < y1 || y3 > y2) return 0L;

      //(x3, ?, x2, ?)
      int yL = Math.max(y1, y3);
      int yH = Math.min(y2, y4);
      int xH = Math.min(x2, x4);

      return f(x3, yL, xH, yH);
  }
  //return #black cells in rectangle
  private long f(int x1, int y1, int x2, int y2) {
      long dx = 1L + x2 - x1;
      long dy = 1L + y2 - y1;
      if (dx % 2 == 0 || dy % 2 == 0 || (x1 + y1) % 2 == 0)
          return 1L * dx * dy / 2;
      return 1L * dx * dy / 2 + 1;
  }

  private int distM(int x, int y, int xx, int yy) {
      return abs(x - xx) + abs(y - yy);
  }

  private boolean less(int x, int y, int xx, int yy) {
      return x < xx || y > yy;
  }

  private int mul(int x, int y) {
      return (int)(1L * x * y % MOD);
  }

  private int nBit1(int v) {
      int v0 = v;
      int c = 0;
      while (v != 0) {
          ++c;
          v = v & (v - 1);
      }
      return c;
  }

  private long abs(long v) {
      return v > 0 ? v : -v;
  }

  private int abs(int v) {
      return v > 0 ? v : -v;
  }

  private int common(int v) {
      int c = 0;
      while (v != 1) {
          v = (v >>> 1);
          ++c;
      }

      return c;
  }

  private void reverse(char[] a, int i, int j) {
      while (i < j) {
          swap(a, i++, j--);
      }
  }

  private void swap(char[] a, int i, int j) {
      char t = a[i];
      a[i] = a[j];
      a[j] = t;
  }

  private int gcd(int x, int y) {
      if (y == 0) return x;
      return gcd(y, x % y);
  }
  private long gcd(long x, long y) {
      if (y == 0) return x;
      return gcd(y, x % y);
  }
  private int max(int a, int b) {
      return a >  b ? a : b;
  }

  private long max(long a, long b) {
      return a >  b ? a : b;
  }

  private int min(int a, int b) {
      return a >  b ? b : a;
  }

  private long min(long a, long b) {
      return a >  b ? b : a;
  }

  static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader(BufferedReader in)
        {
            br = in;
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    String line = br.readLine();
                    if (line == null || line.length() == 0) return "";
                    st = new StringTokenizer(line);
                }
                catch (IOException  e)
                {
                    return "";
                    //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)
            {
                return null;
                //e.printStackTrace();
            }
            return str;
        }
    }
}


import java.util.*;
import java.math.*;
import static java.lang.Character.isDigit;
import static java.lang.Character.isLowerCase;
import static java.lang.Character.isUpperCase;
import static java.lang.Math.*;
import static java.math.BigInteger.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static java.lang.Character.isDigit;

public class Main{
    static void debug(Object...os){
        System.err.println(deepToString(os));
    }
    int[] maxMove=new int[3];
    int[] power=new int[3];
    void run(){
        E init = new E();
        init.xs=new int[3];
        for(int i=0;i<3;i++) {
            init.xs[i]=nextInt();maxMove[i]=nextInt();power[i]=nextInt();
        }
        init.lift=new int[3];
        fill(init.lift,-1);
        init.lifted=new boolean[3];
        init.throwed=new boolean[3];
        init.moved=new boolean[3];
        dfs(init);
        System.out.println(res);
    }
    int res = 0;
    HashSet<Long> set=new HashSet<Long>();
    void dfs(E e) {
        if(set.contains(e.hash()))return;
        set.add(e.hash());
        if(e.reachable()<res)return;
        res = max(res,e.getmaxX());
        for(int i=0;i<3;i++) {
            // move
            boolean ok=true;
            if(e.moved[i])ok=false;
            if(e.lift[i]!=-1)ok=false;
            if(e.lifted[i])ok=false;
            if(ok) {
                ArrayList<Integer> cand = new ArrayList<Integer>();
                cand.add(e.xs[i]-maxMove[i]);
                cand.add(e.xs[i]+maxMove[i]);
                for(int j=0;j<3;j++)if(i!=j)cand.add(e.xs[j]-1);
                for(int j=0;j<3;j++)if(i!=j)cand.add(e.xs[j]+1);
                for(int j : cand)if(e.xs[i]-maxMove[i]<=j && j<=e.xs[i]+maxMove[i]) {
//              for(int j=e.xs[i]-maxMove[i];j<=e.xs[i]+maxMove[i];j++) {
                    if(j<0)continue;
                    E ne = e.myClone();
                    ne.xs[i] = j;
                    ne.moved[i] = true;
                    dfs(ne);
                }
            }
            // lift
            ok=true;
            if(e.throwed[i])ok=false;
            if(e.lift[i]!=-1)ok=false;
            if(e.lifted[i])ok=false;
            if(ok)for(int j=0;j<3;j++)if(i!=j) {
                if(abs(e.xs[i]-e.xs[j])!=1)continue;
                if(e.lifted[j])continue;
                E ne = e.myClone();
                ne.lift[i] = j;
                ne.lifted[j] = true;
                dfs(ne);
            }
            // throw
            ok=true;
            if(e.lifted[i])ok=false;
            if(e.lift[i]==-1)ok=false;
            if(ok) {
                assert !e.throwed[i];
//              ArrayList<Integer> cand = new ArrayList<Integer>();
//              cand.add(e.xs[i]-power[i]);
//              cand.add(e.xs[i]+power[i]);
//              for(int j=0;j<3;j++)if(i!=j)cand.add(e.xs[j]-1);
//              for(int j=0;j<3;j++)if(i!=j)cand.add(e.xs[j]+1);
//              for(int j:cand)if(e.xs[i]-power[i]<=j && j<=e.xs[i]+power[i]){
                for(int j=e.xs[i]-power[i];j<=e.xs[i]+power[i];j++) {
                    if(j<0)continue;
                    E ne = e.myClone();
                    ne.xs[ne.lift[i]] = j;
                    ne.lifted[ne.lift[i]] = false;
                    ne.lift[i] = -1;
                    ne.throwed[i] = true;
                    dfs(ne);
                }
            }
        }
    }

    class E{
        int[] xs;
        int[] lift;
        boolean[] lifted;
        boolean[] moved;
        boolean[] throwed;
        E myClone() {
            E res=new E();
            res.xs = xs.clone();
            res.lift=lift.clone();
            res.lifted=lifted.clone();
            res.moved=moved.clone();
            res.throwed=throwed.clone();
            return res;
        }
        public int reachable(){
            int x=getmaxX();
            for(int i=0;i<3;i++) {
                if(!moved[i])x += maxMove[i];
                if(!throwed[i])x += power[i];
            }
            return x;
        }
        public int getmaxX(){
            int res=Integer.MIN_VALUE;
            for(int x:xs)res=max(res,x);
            return res;
        }
        long hash=-1;
        long hash() {
            if(hash!=-1)return hash;
            hash=0;
            for(int x:xs)hash=hash<<6|x;
            for(int x:lift)hash=hash<<2|x+1;
            for(boolean b:lifted)hash=hash<<1|(b?1:0);
            for(boolean b:moved)hash=hash<<1|(b?1:0);
            for(boolean b:throwed)hash=hash<<1|(b?1:0);
            return hash;
        }

        public int hashCode(){
            final int prime=31;
            int result=1;
            result=prime*result+getOuterType().hashCode();
            result=prime*result+Arrays.hashCode(lift);
            result=prime*result+Arrays.hashCode(lifted);
            result=prime*result+Arrays.hashCode(moved);
            result=prime*result+Arrays.hashCode(throwed);
            result=prime*result+Arrays.hashCode(xs);
            return result;
        }
        public String toString(){
            return "E [lift="+Arrays.toString(lift)+", lifted="+Arrays.toString(lifted)+", moved="
            +Arrays.toString(moved)+", throwed="+Arrays.toString(throwed)+", xs="+Arrays.toString(xs)+"]";
        }
        public boolean equals(Object obj){
            if(this==obj) return true;
            if(obj==null) return false;
            if(getClass()!=obj.getClass()) return false;
            E other=(E)obj;
            if(!getOuterType().equals(other.getOuterType())) return false;
            if(!Arrays.equals(lift,other.lift)) return false;
            if(!Arrays.equals(lifted,other.lifted)) return false;
            if(!Arrays.equals(moved,other.moved)) return false;
            if(!Arrays.equals(throwed,other.throwed)) return false;
            if(!Arrays.equals(xs,other.xs)) return false;
            return true;
        }
        private Main getOuterType(){
            return Main.this;
        }

    }

    int nextInt(){
        try{
            int c=System.in.read();
            if(c==-1) return c;
            while(c!='-'&&(c<'0'||'9'<c)){
                c=System.in.read();
                if(c==-1) return c;
            }
            if(c=='-') return -nextInt();
            int res=0;
            do{
                res*=10;
                res+=c-'0';
                c=System.in.read();
            }while('0'<=c&&c<='9');
            return res;
        }catch(Exception e){
            return -1;
        }
    }

    long nextLong(){
        try{
            int c=System.in.read();
            if(c==-1) return -1;
            while(c!='-'&&(c<'0'||'9'<c)){
                c=System.in.read();
                if(c==-1) return -1;
            }
            if(c=='-') return -nextLong();
            long res=0;
            do{
                res*=10;
                res+=c-'0';
                c=System.in.read();
            }while('0'<=c&&c<='9');
            return res;
        }catch(Exception e){
            return -1;
        }
    }

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

    String next(){
        try{
            StringBuilder res=new StringBuilder("");
            int c=System.in.read();
            while(Character.isWhitespace(c))
                c=System.in.read();
            do{
                res.append((char)c);
            }while(!Character.isWhitespace(c=System.in.read()));
            return res.toString();
        }catch(Exception e){
            return null;
        }
    }

    String nextLine(){
        try{
            StringBuilder res=new StringBuilder("");
            int c=System.in.read();
            while(c=='\r'||c=='\n')
                c=System.in.read();
            do{
                res.append((char)c);
                c=System.in.read();
            }while(c!='\r'&&c!='\n');
            return res.toString();
        }catch(Exception e){
            return null;
        }
    }
    public static void main(String[] args){
        new Main().run();
    }
}


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

public class Main implements Runnable {

    private void solve() throws IOException {
        int x = nextInt();
        int y = nextInt();
        int n = nextInt();

        double minRest = 100;
        long minB = 0;
        long minA = 0;
        for (int i = 1; i <= n; i++) {
            long nk = nok(i, y);
            long td = x * (nk / y);
            long ii = nk / i;

            long tc = td / ii;
            long tr = td % ii;
            if (tr * 2 > ii) {
                tc++;
                tr = ii - tr;
            }
            double rest = tr;
            rest = rest / nk;
            if (rest < minRest) {
                minRest = rest;
                minB = i;
                minA = tc;
            }
        }
        writer.println(minA + "/" + minB);
    }

    long nod(long a, long b) {
        if (a < b) {
            long t = a;
            a = b;
            b = t;
        }
        if (a % b == 0) {
            return b;
        }
        return nod(b, a % b);
    }

    long nok(long a, long b) {
        return (a / nod(a, b)) * b;
    }

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

    BufferedReader reader;
    StringTokenizer tokenizer;
    PrintWriter writer;

    @Override
    public void run() {
        try {
            reader = new BufferedReader(new InputStreamReader(System.in));
            tokenizer = null;
            writer = new PrintWriter(System.out);
            solve();
            reader.close();
            writer.close();
        }
        catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

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

    private String nextToken() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }

}


import java.util.Scanner;

/**
 * Created by abgupta on 3/19/17.
 */
public class C_652_A {

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

        int a = in.nextInt();
        int b = in.nextInt();
        int dh = h2-h1;

        if (a<=b) {
            if (8*a<dh) {
                System.out.println(-1);

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

            return;

        }

        int lo=0,hi= (int) 1e5;

        while(lo<hi) {
            int mid = lo + (hi-lo)/2;
            if (p(mid, dh, a ,b)) hi=mid; else lo=mid+1;
        }
        System.out.println(lo);
    }

    private static boolean p(int mid, int dh, int a, int b) {
        long l = 1l*(mid)*(a-b)*12 + 8*a;
        return l >= dh;
    }
}


 import java.util.*;

public class BruteForce{

    public static Scanner in=new Scanner(System.in);
    public static void main(String[]args){
        long n=in.nextLong();
        long ans=1+(6*n)+((n*(n-1))/2)*6;
        System.out.println(ans);
    }

}


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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author George Marcus
 */
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();
	}
}

class TaskC {
    private int[] computer;
    private boolean[] v;
    private int[] allowed;
    private int[] Gin;
    private boolean[][] edge;
    private int N;
    private ArrayList<Integer>[] graph;

    public void solve(int testNumber, Scanner in, PrintWriter out) {
        N = in.nextInt();
        v = new boolean[N + 1];
        allowed = new int[N + 1];
        Gin = new int[N + 1];
        computer = new int[N + 1];
        edge = new boolean[N + 1][N + 1];
        for(int i = 1; i <= N; i++)
            computer[i] = in.nextInt();
        graph = new ArrayList[N + 1];
        for(int i = 1; i <= N; i++)
            graph[i] = new ArrayList<Integer>();
        int completed = 0;
        int k, t, start = 0;
        for(int i = 1; i <= N; i++) {
            k = in.nextInt();
            for(int j = 0; j < k; j++) {
                t = in.nextInt();
                if(!edge[t][i]) {
                    graph[t].add(i);
                    Gin[i]++;
                }
                edge[t][i] = true;
            }
        }

        int r1 = go(1);
        int r2 = go(2);
        int r3 = go(3);

        int res = Math.min(r1, Math.min(r2, r3));

        out.print(res);
	}

    private int go(int start) {
        int comp = start;
        int completed = 0;
        int time = 0;
        boolean reset = false;
        int[] need = new int[N + 1];
        System.arraycopy(Gin, 0, need, 0, N + 1);

        while(completed < N) {
            for(int i = 1; i <= N; i++)
                if(need[i] == 0 && computer[i] == comp) {
                    need[i] = -1;
                    time++;
                    completed++;

                    for(int j = 0; j < graph[i].size(); j++) {
                        need[graph[i].get(j)]--;
                        if(need[graph[i].get(j)] == 0 && computer[graph[i].get(j)] == comp)
                            reset = true;
                    }

                    if(reset)
                        i = 0;
                }

            time++;
            comp = comp % 3 + 1;
        }

        return time - 1;
    }

}


//*******************************************************************
// Welcome to CompileJava!
// If you experience any issues, please contact us ('More Info')  -->
//*******************************************************************

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

public class CF328B {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));

String line = br.readLine();
int[] createCount = new int[10];
for (int i = 0; i < line.length(); i++) {
createCount[line.charAt(i) - '0']++;
}
createCount[2] += createCount[5];
createCount[6] += createCount[9];
createCount[5] = 0;
createCount[9] = 0;

int[] count = new int[10];
line = br.readLine();
for (int i = 0; i < line.length(); i++) {
count[line.charAt(i) - '0']++;
}
count[2] += count[5];
count[6] += count[9];
count[5] = 0;
count[9] = 0;

int min = Integer.MAX_VALUE;
for (int i = 0; i < 10; i++) {
if (createCount[i] == 0) continue;
min = Math.min(min, count[i] / createCount[i]);
}

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

/*
import java.lang.Math; // headers MUST be above the first class

// one class needs to have a main() method
public ss HelloWorld
{
  // arguments are passed using the text field below this editor
  public static void main(String[] args)
  {
    OtherClass myObject = new OtherClass("Hello World!");
    System.out.print(myObject);
  }
}

// you cn add other public classes to this editor in any order
public ass OtherClass
{
  private String message;
  private boolean answer = false;
  public OtherClass(String input)
  {
    message = "Why, " + input + " Isn't this something?";
  }
  public String toString()
  {
    return message;
  }
}
*/


//created by Whiplash99
import java.io.*;
import java.util.*;
public class A
{
    private static ArrayList<Long> list, subsets;
    private static void allSubsets(int i, long sum)
    {
        if(i==list.size())
        {
            subsets.add(sum);
            return;
        }

        allSubsets(i+1,sum+list.get(i));
        allSubsets(i+1,sum);
    }
    private static boolean check(long M, long W, long x)
    {
        if(x==M) return true;

        boolean flag=true;
        x+=M;
        while (x>0)
        {
            if(x%W>1)
            {
                flag=false;
                break;
            }
            x/=W;
        }

        return flag;
    }
    public static void main(String[] args) throws Exception
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

        int i,N;

        String[] s=br.readLine().trim().split(" ");
        long W=Long.parseLong(s[0]);
        long M=Long.parseLong(s[1]);

        if(W==2)
        {
            System.out.println("YES");
            System.exit(0);
        }

        list=new ArrayList<>();
        list.add(1L); list.add(W);

        long cur=W;
        final long MAX=(long)(1e10);

        while (true)
        {
            cur*=W;
            if(cur<0||cur>MAX) break;

            list.add(cur);
        }

        subsets = new ArrayList<>();
        allSubsets(0,0);

        boolean flag=false;
        for(long x: subsets)
        {
            flag |= check(M, W, x);
            if(flag) break;
        }

        System.out.println(flag?"YES":"NO");
    }
}


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

/*
 * 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 Ivan
 */
public class secondProblem {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException {
        Reader.init(System.in);
        long players=Reader.nextInt();
        long teams=Reader.nextInt();
        long max,min;
       // long[] maxTeams=new long[teams];
        max=(players-teams+1)*(players-teams)/2;
       // int[] minTeams=new int[teams];
        long mem=players/teams;
        long temp=teams;
        players-=mem*teams;
        min=0;
        if(players!=0)
            min+=players*(mem+1)*mem/2;
        min+=(temp-players)*mem*(mem-1)/2;
       // for(int i=0;i<teams;i++)
         //   System.out.println(minTeams[i]);
       // max=maxTeams[0]*(maxTeams[0]-1)/2;

        System.out.println(min+" "+max);
    }

}

class Reader {
    static BufferedReader reader;
    static StringTokenizer tokenizer;

    /** call this method to initialize reader for InputStream */
    static void init(InputStream input) {
        reader = new BufferedReader(
                     new InputStreamReader(input) );
        tokenizer = new StringTokenizer("");
    }

    /** get next word */
    static String next() throws IOException {
        while ( ! tokenizer.hasMoreTokens() ) {
            //TODO add check for eof if necessary
            tokenizer = new StringTokenizer(
                   reader.readLine() );
        }
        return tokenizer.nextToken();
    }

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

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


import java.util.Scanner;
/*
 20.12.68 20.12.50
 20.12.68 21.12.50
 20.12.68 19.12.50
 */
public class b30 {
	static int[][] days;
	static int[] comp, birth;
	static boolean[] used;
	static int[] attempt;

	public static void main(String[] args) {
		comp= new int[3];
		birth = new int[3];
		used = new boolean[3];
		attempt = new int[3];
		days = new int[][] {
				{ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
				{ 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } };
		Scanner in = new Scanner(System.in);
		int i = 0;
		for (String string : in.next().split("\\.")) {
			comp[i++] = Integer.parseInt(string);
		}
		i = 0;
		for (String string : in.next().split("\\.")) {
			birth[i++] = Integer.parseInt(string);
		}
		in.close();

		System.out.println(recurse(2) ? "YES" : "NO");
	}

	private static boolean recurse(int i) {
		if (i == -1) {
			int ydiff = comp[2] - attempt[2];

			if (comp[1] < attempt [1] || (comp[1] == attempt[1] && comp[0] < attempt[0]))
					ydiff--;
//			System.out.printf("%d:%d:%d - %d\n", attempt[0], attempt[1], attempt[2], ydiff);
			return ydiff >= 18;
		} else {
			boolean works = false;
			for (int j = 0; j < 3; j++) {
				if (!used[j]) {
					if (i == 0) {
						int arr = attempt[2] % 4 == 0 ? 1 : 0;
						if (birth[j] > days[arr][attempt[1]-1])
							continue;
					}
					if (i == 1 && birth[j] > 12)
						continue;
					used[j] = true;
					attempt[i] = birth[j];
					works |= recurse(i - 1);
					used[j] = false;
				}
			}
			return works;
		}
	}
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Random;
import java.util.Map;
import java.io.OutputStreamWriter;
import java.io.OutputStream;
import java.util.stream.LongStream;
import java.util.Collection;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.stream.Stream;
import java.io.Closeable;
import java.io.Writer;
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 << 27);
        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);
            GXMouseInTheCampus solver = new GXMouseInTheCampus();
            solver.solve(1, in, out);
            out.close();
        }
    }

    static class GXMouseInTheCampus {
        LongHashMap mu = new LongHashMap(100000, false);
        LongHashMap euler = new LongHashMap(100000, false);
        long[] primes;

        {
            mu.put(1, 1);
            euler.put(1, 1);
        }

        public long oneOfPrimeFactor(long x) {
            for (long p : primes) {
                if (x % p == 0) {
                    return p;
                }
            }
            return x;
        }

        public void populate(long x) {
            long factor = oneOfPrimeFactor(x);
            long cnt = 0;
            long y = x;
            while (y % factor == 0) {
                cnt++;
                y /= factor;
            }
            if (cnt > 1) {
                mu.put(x, 0);
            } else {
                mu.put(x, -mu(y));
            }
            euler.put(x, euler(y) * (x / y - x / y / factor));
        }

        public long mu(long x) {
            long ans = mu.getOrDefault(x, -1);
            if (ans == -1) {
                populate(x);
                ans = mu.get(x);
            }
            return ans;
        }

        public long euler(long x) {
            long ans = euler.getOrDefault(x, -1);
            if (ans == -1) {
                populate(x);
                ans = euler.get(x);
            }
            return ans;
        }

        public void solve(int testNumber, FastInput in, FastOutput out) {
            long m = in.readLong();
            long x = in.readLong();

            primes = new LongPollardRho().findAllFactors(m).keySet()
                    .stream().mapToLong(Long::longValue).toArray();
            LongList allFactorOfM = new LongList(20000);
            LongList tmpList = new LongList(20000);
            LongList allPossiblePrimeFactor = new LongList();
            for (long p : primes) {
                allPossiblePrimeFactor.add(p);
                allPossiblePrimeFactor.addAll(Factorization.factorizeNumberPrime(p - 1));
            }
            allPossiblePrimeFactor.unique();

            collect(allFactorOfM, m, 0);
            LongPower power = new LongPower(ILongModular.getInstance(m));

            long total = 1;
            for (int i = 0; i < allFactorOfM.size(); i++) {
                long g = allFactorOfM.get(i);
                if (g == m) {
                    continue;
                }
                long mg = m / g;
                tmpList.clear();
                collect(tmpList, mg, 0);
                long cnt = 0;
                for (int j = tmpList.size() - 1; j >= 0; j--) {
                    long t = tmpList.get(j);
                    cnt += mu(t) * ((m - 1) / (t * g));
                }

                tmpList.clear();
                long euler = euler(mg);
                LongList primeFactors = tmpList;
                for (int j = 0; j < allPossiblePrimeFactor.size(); j++) {
                    long p = allPossiblePrimeFactor.get(j);
                    if (euler % p == 0) {
                        primeFactors.add(p);
                    }
                }

                long n = euler;
                for (int j = 0; j < primeFactors.size(); j++) {
                    long p = primeFactors.get(j);
                    while (n % p == 0 && power.pow(x, n / p) % mg == 1) {
                        n /= p;
                    }
                }

                if (cnt % n != 0) {
                    throw new IllegalStateException();
                }
                total += cnt / n;
            }

            out.println(total);
        }

        public void collect(LongList list, long x, int i) {
            if (i == primes.length) {
                list.add(x);
                return;
            }
            collect(list, x, i + 1);
            while (x % primes[i] == 0) {
                x /= primes[i];
                collect(list, x, i + 1);
            }
        }

    }

    static class DigitUtils {
        private DigitUtils() {
        }

        public static long round(double x) {
            if (x >= 0) {
                return (long) (x + 0.5);
            } else {
                return (long) (x - 0.5);
            }
        }

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

        public static long mulMod(long a, long b, long mod) {
            long k = DigitUtils.round((double) a / mod * b);
            return DigitUtils.mod(a * b - k * mod, mod);
        }

    }

    static class FastOutput implements AutoCloseable, Closeable, Appendable {
        private StringBuilder cache = new StringBuilder(10 << 20);
        private final Writer os;

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

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

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

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

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

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

        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 LongPower {
        final ILongModular modular;

        public LongPower(ILongModular modular) {
            this.modular = modular;
        }

        public long pow(long x, long n) {
            if (n == 0) {
                return 1;
            }
            long r = pow(x, n >> 1);
            r = modular.mul(r, r);
            if ((n & 1) == 1) {
                r = modular.mul(r, x);
            }
            return r;
        }

    }

    static class Factorization {
        public static LongList factorizeNumberPrime(long x) {
            LongList ans = new LongList();
            for (long i = 2; i * i <= x; i++) {
                if (x % i != 0) {
                    continue;
                }
                ans.add(i);
                while (x % i == 0) {
                    x /= i;
                }
            }
            if (x > 1) {
                ans.add(x);
            }
            return ans;
        }

    }

    static class LongHashMap {
        private int[] slot;
        private int[] next;
        private long[] keys;
        private long[] values;
        private int alloc;
        private boolean[] removed;
        private int mask;
        private int size;
        private boolean rehash;

        public LongHashMap(int cap, boolean rehash) {
            this.mask = (1 << (32 - Integer.numberOfLeadingZeros(cap - 1))) - 1;
            slot = new int[mask + 1];
            next = new int[cap + 1];
            keys = new long[cap + 1];
            values = new long[cap + 1];
            removed = new boolean[cap + 1];
            this.rehash = rehash;
        }

        private void doubleCapacity() {
            int newSize = Math.max(next.length + 10, next.length * 2);
            next = Arrays.copyOf(next, newSize);
            keys = Arrays.copyOf(keys, newSize);
            values = Arrays.copyOf(values, newSize);
            removed = Arrays.copyOf(removed, newSize);
        }

        public void alloc() {
            alloc++;
            if (alloc >= next.length) {
                doubleCapacity();
            }
            next[alloc] = 0;
            removed[alloc] = false;
            size++;
        }

        private void rehash() {
            int[] newSlots = new int[Math.max(16, slot.length * 2)];
            int newMask = newSlots.length - 1;
            for (int i = 0; i < slot.length; i++) {
                if (slot[i] == 0) {
                    continue;
                }
                int head = slot[i];
                while (head != 0) {
                    int n = next[head];
                    int s = hash(keys[head]) & newMask;
                    next[head] = newSlots[s];
                    newSlots[s] = head;
                    head = n;
                }
            }
            this.slot = newSlots;
            this.mask = newMask;
        }

        private int hash(long x) {
            int h = Long.hashCode(x);
            return h ^ (h >>> 16);
        }

        public void put(long x, long y) {
            put(x, y, true);
        }

        public void put(long x, long y, boolean cover) {
            int h = hash(x);
            int s = h & mask;
            if (slot[s] == 0) {
                alloc();
                slot[s] = alloc;
                keys[alloc] = x;
                values[alloc] = y;
            } else {
                int index = findIndexOrLastEntry(s, x);
                if (keys[index] != x) {
                    alloc();
                    next[index] = alloc;
                    keys[alloc] = x;
                    values[alloc] = y;
                } else if (cover) {
                    values[index] = y;
                }
            }
            if (rehash && size >= slot.length) {
                rehash();
            }
        }

        public long getOrDefault(long x, long def) {
            int h = hash(x);
            int s = h & mask;
            if (slot[s] == 0) {
                return def;
            }
            int index = findIndexOrLastEntry(s, x);
            return keys[index] == x ? values[index] : def;
        }

        public long get(long x) {
            return getOrDefault(x, 0);
        }

        private int findIndexOrLastEntry(int s, long x) {
            int iter = slot[s];
            while (keys[iter] != x) {
                if (next[iter] != 0) {
                    iter = next[iter];
                } else {
                    return iter;
                }
            }
            return iter;
        }

        public LongEntryIterator iterator() {
            return new LongEntryIterator() {
                int index = 1;
                int readIndex = -1;

                public boolean hasNext() {
                    while (index <= alloc && removed[index]) {
                        index++;
                    }
                    return index <= alloc;
                }

                public long getEntryKey() {
                    return keys[readIndex];
                }

                public long getEntryValue() {
                    return values[readIndex];
                }

                public void next() {
                    if (!hasNext()) {
                        throw new IllegalStateException();
                    }
                    readIndex = index;
                    index++;
                }
            };
        }

        public String toString() {
            LongEntryIterator iterator = iterator();
            StringBuilder builder = new StringBuilder("{");
            while (iterator.hasNext()) {
                iterator.next();
                builder.append(iterator.getEntryKey()).append("->").append(iterator.getEntryValue()).append(',');
            }
            if (builder.charAt(builder.length() - 1) == ',') {
                builder.setLength(builder.length() - 1);
            }
            builder.append('}');
            return builder.toString();
        }

    }

    static class LongPollardRho {
        LongMillerRabin mr = new LongMillerRabin();
        ILongModular modular;
        Random random = new Random();

        public long findFactor(long n) {
            if (mr.mr(n, 3)) {
                return n;
            }
            modular = ILongModular.getInstance(n);
            while (true) {
                long f = findFactor0((long) (random.nextDouble() * n), (long) (random.nextDouble() * n), n);
                if (f != -1) {
                    return f;
                }
            }
        }

        private long findFactor0(long x, long c, long n) {
            long xi = x;
            long xj = x;
            int j = 2;
            int i = 1;
            while (i < n) {
                i++;
                xi = modular.plus(modular.mul(xi, xi), c);
                long g = GCDs.gcd(n, Math.abs(xi - xj));
                if (g != 1 && g != n) {
                    return g;
                }
                if (i == j) {
                    j = j << 1;
                    xj = xi;
                }
            }
            return -1;
        }

        public Map<Long, Long> findAllFactors(long n) {
            Map<Long, Long> map = new HashMap();
            findAllFactors(map, n);
            return map;
        }

        private void findAllFactors(Map<Long, Long> map, long n) {
            if (n == 1) {
                return;
            }
            long f = findFactor(n);
            if (f == n) {
                Long value = map.get(f);
                if (value == null) {
                    value = 1L;
                }
                map.put(f, value * f);
                return;
            }
            findAllFactors(map, f);
            findAllFactors(map, n / f);
        }

    }

    static class GCDs {
        private GCDs() {
        }

        public static long gcd(long a, long b) {
            return a >= b ? gcd0(a, b) : gcd0(b, a);
        }

        private static long gcd0(long a, long b) {
            return b == 0 ? a : gcd0(b, a % b);
        }

    }

    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 long readLong() {
            int sign = 1;

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

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

            return val;
        }

    }

    static interface LongEntryIterator {
        boolean hasNext();

        void next();

        long getEntryKey();

        long getEntryValue();

    }

    static class LongModular implements ILongModular {
        final long m;

        public LongModular(long m) {
            this.m = m;
        }

        public long mul(long a, long b) {
            return b == 0 ? 0 : ((mul(a, b >> 1) << 1) % m + a * (b & 1)) % m;
        }

        public long plus(long a, long b) {
            return valueOf(a + b);
        }

        public long valueOf(long a) {
            a %= m;
            if (a < 0) {
                a += m;
            }
            return a;
        }

    }

    static class LongMillerRabin {
        ILongModular modular;
        LongPower power;
        Random random = new Random();

        public boolean mr(long n, int s) {
            if (n <= 1) {
                return false;
            }
            if (n == 2) {
                return true;
            }
            if (n % 2 == 0) {
                return false;
            }
            modular = ILongModular.getInstance(n);
            power = new LongPower(modular);
            for (int i = 0; i < s; i++) {
                long x = (long) (random.nextDouble() * (n - 2) + 2);
                if (!mr0(x, n)) {
                    return false;
                }
            }
            return true;
        }

        private boolean mr0(long x, long n) {
            long exp = n - 1;
            while (true) {
                long y = power.pow(x, exp);
                if (y != 1 && y != n - 1) {
                    return false;
                }
                if (y != 1 || exp % 2 == 1) {
                    break;
                }
                exp = exp / 2;
            }
            return true;
        }

    }

    static class LongModularDanger implements ILongModular {
        final long m;

        public LongModularDanger(long m) {
            this.m = m;
        }

        public long mul(long a, long b) {
            return DigitUtils.mulMod(a, b, m);
        }

        public long plus(long a, long b) {
            return valueOf(a + b);
        }

        public long valueOf(long a) {
            a %= m;
            if (a < 0) {
                a += m;
            }
            return a;
        }

    }

    static class LongList implements Cloneable {
        private int size;
        private int cap;
        private long[] data;
        private static final long[] EMPTY = new long[0];

        public LongList(int cap) {
            this.cap = cap;
            if (cap == 0) {
                data = EMPTY;
            } else {
                data = new long[cap];
            }
        }

        public LongList(LongList list) {
            this.size = list.size;
            this.cap = list.cap;
            this.data = Arrays.copyOf(list.data, size);
        }

        public LongList() {
            this(0);
        }

        public void ensureSpace(int req) {
            if (req > cap) {
                while (cap < req) {
                    cap = Math.max(cap + 10, 2 * cap);
                }
                data = Arrays.copyOf(data, cap);
            }
        }

        private void checkRange(int i) {
            if (i < 0 || i >= size) {
                throw new ArrayIndexOutOfBoundsException();
            }
        }

        public long get(int i) {
            checkRange(i);
            return data[i];
        }

        public void add(long x) {
            ensureSpace(size + 1);
            data[size++] = x;
        }

        public void addAll(long[] x, int offset, int len) {
            ensureSpace(size + len);
            System.arraycopy(x, offset, data, size, len);
            size += len;
        }

        public void addAll(LongList list) {
            addAll(list.data, 0, list.size);
        }

        public void sort() {
            if (size <= 1) {
                return;
            }
            Randomized.shuffle(data, 0, size);
            Arrays.sort(data, 0, size);
        }

        public void unique() {
            if (size <= 1) {
                return;
            }

            sort();
            int wpos = 1;
            for (int i = 1; i < size; i++) {
                if (data[i] != data[wpos - 1]) {
                    data[wpos++] = data[i];
                }
            }
            size = wpos;
        }

        public int size() {
            return size;
        }

        public long[] toArray() {
            return Arrays.copyOf(data, size);
        }

        public void clear() {
            size = 0;
        }

        public String toString() {
            return Arrays.toString(toArray());
        }

        public boolean equals(Object obj) {
            if (!(obj instanceof LongList)) {
                return false;
            }
            LongList other = (LongList) obj;
            return SequenceUtils.equal(data, 0, size - 1, other.data, 0, other.size - 1);
        }

        public int hashCode() {
            int h = 1;
            for (int i = 0; i < size; i++) {
                h = h * 31 + Long.hashCode(data[i]);
            }
            return h;
        }

        public LongList clone() {
            LongList ans = new LongList();
            ans.addAll(this);
            return ans;
        }

    }

    static class SequenceUtils {
        public static boolean equal(long[] a, int al, int ar, long[] b, int bl, int br) {
            if ((ar - al) != (br - bl)) {
                return false;
            }
            for (int i = al, j = bl; i <= ar; i++, j++) {
                if (a[i] != b[j]) {
                    return false;
                }
            }
            return true;
        }

    }

    static class Randomized {
        private static Random random = new Random(0);

        public static void shuffle(long[] data, int from, int to) {
            to--;
            for (int i = from; i <= to; i++) {
                int s = nextInt(i, to);
                long tmp = data[i];
                data[i] = data[s];
                data[s] = tmp;
            }
        }

        public static int nextInt(int l, int r) {
            return random.nextInt(r - l + 1) + l;
        }

    }

    static interface ILongModular {
        long plus(long a, long b);

        long mul(long a, long b);

        static ILongModular getInstance(long mod) {
            //return new LongModularDanger(mod);
            return mod <= (1L << 54) ? new LongModularDanger(mod) : new LongModular(mod);
        }

    }
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.StringTokenizer;

public class Task_1749_D {

    public static final long MOD = 998244353L;
    public static final BigInteger MOD_BIG = BigInteger.valueOf(MOD);

    public static void main(String[] args) throws Exception {
        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            StringTokenizer tok = new StringTokenizer(br.readLine());
            int n = Integer.parseInt(tok.nextToken());
            long m = Long.parseLong(tok.nextToken());

            BigInteger result = BigInteger.ZERO;
            BigInteger mBig = BigInteger.valueOf(m);
            BigInteger currValue = BigInteger.valueOf(m);
            long currDiv = 1L;
            boolean[] erat = eratosthenes(n);
            BigInteger total = BigInteger.valueOf(m);
            for (int i = 2; i <= n; i++) {
                total = total.multiply(mBig).remainder(MOD_BIG).add(MOD_BIG);
                if (!erat[i]) {
                    currDiv *= i;
                }
                currValue = currValue.multiply(BigInteger.valueOf(m / currDiv)).remainder(MOD_BIG);
                result = result.add(total).subtract(currValue).remainder(MOD_BIG);
            }

            System.out.println(result.longValue());
        }
    }

    private static boolean[] eratosthenes(int n) {
        boolean[] res = new boolean[n + 1];
        for (int i = 2; i * i <= n ; i++) {
            if(!res[i]) {
                for (int j = i * i; j <= n ; j += i) {
                    res[j] = true;
                }
            }
        }
        return res;
    }
}


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

public class ivanTheFool {
    public static long mod = 1000000007;
    public static void fout(long x){
        System.out.println(x);
    }
    /**-----------fast reader------------*/
    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;
        }
    }
    /**-----end of fast reader----------------*/

    public static long pmod(long  x,long  y){
        long r = 1;
        while(y > 0){
            if(y%2 == 1){
                r = (r * x)%mod;
            }
            x = (x * x)%mod;
            y >>= 1;
        }
        return r;
    }

    public static void main(String[] args) {
        FastReader rd = new FastReader();
        long n,m;
        n = rd.nextLong();
        m = rd.nextLong();
        long answer = 0;
        long []fact = new long[200000];
        fact[0] = 1;
        for(long i = 1;i<200000;++i){
            fact[(int)i] = (fact[(int)i-1]*i)%mod;
        }
        answer += 2;//all adj cells are different
        if(m >= 2){
            for(long blk = 1 ; blk <= (m/2);blk++){
                long bins = m - (2*blk) + 1;
                long sub = (fact[(int)(bins + blk -1)]*pmod(fact[(int)blk],mod-(long)2))%mod;
                sub = (sub * pmod(fact[(int)bins-1],mod-(long)2))%mod;
                sub = (2 * sub)%mod;
                //fout(sub);
                answer = (answer + sub)%mod;
            }
        }
        if(n >= 2){
            for(long blk = 1 ; blk <= (n/2);blk++){
                long bins = n - (2*blk) + 1;
                long sub = (fact[(int)(bins + blk -1)]*pmod(fact[(int)blk],mod-(long)2))%mod;
                sub = (sub * pmod(fact[(int)bins-1],mod-(long)2))%mod;
                sub = (2 * sub)%mod;
                answer = (answer + sub)%mod;
            }
        }
        // if(m == 1 ^ n == 1){
        //     answer = (answer + 2)%mod;
        // }
        fout(answer);
    }
}


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

public class CF1342E extends PrintWriter {
	CF1342E() { super(System.out, true); }
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		CF1342E o = new CF1342E(); o.main(); o.flush();
	}

	static final int MD = 998244353;
	int[] ff, gg;
	long power(int a, int k) {
		if (k == 0)
			return 1;
		long p = power(a, k >> 1);
		p = p * p % MD;
		if ((k & 1) == 1)
			p = p * a % MD;
		return p;
	}
	long ch(int n, int k) {
		return (long) ff[n] * gg[k] % MD * gg[n - k] % MD;
	}
	void main() {
		int n = sc.nextInt();
		long k_ = sc.nextLong();
		if (k_ >= n) {
			println(0);
			return;
		}
		int c = n - (int) k_;
		ff = new int[n + n];
		gg = new int[n + n];
		for (int f = 1, i = 0; i < n + n; i++) {
			gg[i] = (int) power(ff[i] = f, MD - 2);
			f = (int) ((long) f * (i + 1) % MD);
		}
		long ans = 0;
		for (int a = 1; a <= c; a++) {
			long x = power(a, n) * ch(c, a) % MD;
			ans += (c - a) % 2 == 0 ? x : -x;
		}
		if ((ans %= MD) < 0)
			ans += MD;
		ans = ans * ch(n, c) % MD;
		if (k_ > 0)
			ans = ans * 2 % MD;
		println(ans);
	}
}


import java.util.*;

public class B_189_Counting_Rhombi {
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt(),m=sc.nextInt();
        long ans=0;
        for (int i=2;i<=n;i+=2){
            for (int j=2;j<=m;j+=2){
                ans+=(n-i+1)*(m-j+1);
            }
        }
        System.out.println(ans);
    }
}


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.io.InputStream;

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

  static class TaskB {
    char[][] board;

    public void solve(int testNumber, QuickScanner in, QuickWriter out) {
      board = new char[9][9];
      for (int i = 0; i < 9; ++i)
        for (int j = 0; j < 9; ++j) {
          board[i][j] = (char) in.nextNonSpaceChar();
        }
      int x = (in.nextInt() - 1) % 3 * 3;
      int y = (in.nextInt() - 1) % 3 * 3;
      int count = 0;
      if (hasEmpty(x, y)) {
        for (int i = x; i < x + 3; ++i)
          for (int j = y; j < y + 3; ++j)
            if (board[i][j] == '.') {
              board[i][j] = '!';
            }
      } else {
        for (int i = 0; i < 9; ++i)
          for (int j = 0; j < 9; ++j)
            if (board[i][j] == '.') {
              board[i][j] = '!';
            }
      }
      for (int i = 0; i < 9; ++i) {
        if (i > 0 && i % 3 == 0) out.println();
        for (int j = 0; j < 9; ++j) {
          if (j > 0 && j % 3 == 0) out.print(' ');
          out.print(board[i][j]);
        }
        out.println();
      }
    }

    boolean hasEmpty(int x, int y) {
      for (int i = x; i < x + 3; ++i)
        for (int j = y; j < y + 3; ++j) {
          if (board[i][j] == '.') return true;
        }
      return false;
    }

  }

  static class QuickWriter {
    private final PrintWriter writer;

    public QuickWriter(OutputStream outputStream) {
      this.writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
    }

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

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

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

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

  }

  static class QuickScanner {
    private static final int BUFFER_SIZE = 1024;
    private InputStream stream;
    private byte[] buffer;
    private int currentPosition;
    private int numberOfChars;

    public QuickScanner(InputStream stream) {
      this.stream = stream;
      this.buffer = new byte[BUFFER_SIZE];
      this.currentPosition = 0;
      this.numberOfChars = 0;
    }

    public int nextInt() {
      int c = nextNonSpaceChar();
      boolean positive = true;
      if (c == '-') {
        positive = false;
        c = nextChar();
      }
      int res = 0;
      do {
        if (c < '0' || '9' < c) throw new RuntimeException();
        res = res * 10 + (c - '0');
        c = nextChar();
      } while (!isSpaceChar(c));
      return positive ? res : -res;
    }

    public int nextNonSpaceChar() {
      int res = nextChar();
      for (; isSpaceChar(res) || res < 0; res = nextChar()) ;
      return res;
    }

    public int nextChar() {
      if (numberOfChars == -1) {
        throw new RuntimeException();
      }
      if (currentPosition >= numberOfChars) {
        currentPosition = 0;
        try {
          numberOfChars = stream.read(buffer);
        } catch (Exception e) {
          throw new RuntimeException(e);
        }
        if (numberOfChars <= 0) {
          return -1;
        }
      }
      return buffer[currentPosition++];
    }

    public boolean isSpaceChar(int c) {
      return c == ' ' || c == '\t' || isEndOfLineChar(c);
    }

    public boolean isEndOfLineChar(int c) {
      return c == '\n' || c == '\r' || c < 0;
    }

  }
}


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

public class D {

	static final int P = 1_000_000_007;

	void submit() {
		int n = nextInt();
		int[] dp = new int[n + 2];
		dp[0] = 1;
		for (int k = 1; k <= n; k++) {
			int[] nxt = new int[n + 1];
			int need = n + 1 - k;
			for (int i = 0; i <= need + 1; i++) {
				for (int j = 0; i + j - 1 <= need; j++) {
					int prod = (int) ((long) dp[i] * dp[j] % P);

					if (i + j <= need) {
						nxt[i + j] += prod;
						if (nxt[i + j] >= P) {
							nxt[i + j] -= P;
						}
						nxt[i + j] += (int) (2L * prod * (i + j) % P);
						if (nxt[i + j] >= P) {
							nxt[i + j] -= P;
						}

						if (i + j + 1 <= need) {
							nxt[i + j + 1] += prod;
							if (nxt[i + j + 1] >= P) {
								nxt[i + j + 1] -= P;
							}
						}
					}

					if (i + j > 0) {
						int mult = (i + j) * (i + j) - i - j;
						nxt[i + j - 1] += (int) ((long)mult * prod % P);
						if (nxt[i + j - 1] >= P) {
							nxt[i + j - 1] -= P;
						}
					}
				}
			}
			dp = nxt;
//			System.err.println(Arrays.toString(dp));
		}

		out.println(dp[1]);
	}

	void preCalc() {

	}

	void stress() {

	}

	D() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		preCalc();
		submit();
		// stress();
		// test();
		out.close();
	}

	static final Random rng = new Random();

	static int rand(int l, int r) {
		return l + rng.nextInt(r - l + 1);
	}

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

	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;

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

	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}

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

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

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


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.StringTokenizer;

public class Problem1 {

	static long a, b, c;

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		int[] days = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
		HashMap< String, Integer> hm = new HashMap<>();
		hm.put("monday", 1);
		hm.put("tuesday", 2);
		hm.put( "wednesday", 3);
		hm.put("thursday",4);
		hm.put( "friday", 5);
		hm.put( "saturday", 6);
		hm.put("sunday", 7);
		String f = in.next();
		String s = in.next();
		int a = hm.get(f);
		int b = hm.get(s);
		for(int i = 0; i < 12; ++i)
		{
			int rem = (days[i]) % 7;
			if((a + rem) % 7 == b ||  ((a + rem) % 7 == 0 && b== 7 ))
			{
				out.println("YES");
				out.close();
				return;
			}

			if(a == b && rem == 0)
			{
				out.println("YES");
				out.close();
				return;
			}
		}

		out.println("NO");
		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 nextInt() {
	        return Integer.parseInt(next());
	    }

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

	}

}


//codeforces_975B

import java.io.*;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static java.lang.Math.*;

public class acm{

	public static void main(String args[]) throws IOException,FileNotFoundException {
		BufferedReader gi = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter go = new PrintWriter(System.out);
		int[] line = parseArray(gi.readLine().split(" "));
		int div,rem;
		long temp = 0,rez = 0;
		for (int k = 0; k<14; k++){
			if (line[k] == 0){ continue; }
			div = line[k]/14;
			rem = line[k]%14;
			temp = 0;
			for (int j = k+1; j<=k+rem; j++){
				if ((line[j%14]+div+1)%2==0){ temp += line[j%14] + 1 + div; }
			}
			for (int j = k+rem+1; j<14+k; j++){
				if ((line[j%14]+div)%2==0){ temp+= line[j%14] + div; }
			}
			if (div%2==0){temp+=div;}
			rez = max(rez, temp);
		}
		go.println(rez);
		go.close();
	}

	static int[]  parseArray(String[] line){
		int len = line.length;
		int A[] = new int[len];
		int k = 0;
		for (String e : line){
			A[k++] = Integer.parseInt(e);
		}
		return A;
	}

}


/*Author LAVLESH*/
import java.util.*;
import java.io.*;
import java.math.BigInteger;
public class solution{
	static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	static StringTokenizer st=new StringTokenizer("");

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

	static int mod=1000003;
	static int inv(int a){
		return BigInteger.valueOf(a).modInverse(BigInteger.valueOf(mod)).intValue();
	}
	public static void main(String[]args)throws IOException{
		PrintWriter op =new PrintWriter(System.out,true);
		long ans;
		int n=Integer.parseInt(next());
		 int m=Integer.parseInt(next());
		int num=1,den=1;
		 for(int i=1;i<=m;i++)
		 {
			 num=(int)((long)num*(n+i)%mod);
			 den=(int)((long)den*i%mod);
		 }
	ans=(((long)num*inv(den)%mod)+mod)%mod;
		op.println(ans-1);

		 op.close();
  }
}


import java.util.*;
public class A761 {
    public static void main(String []args)
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m =sc.nextInt();
        if(Math.abs(m-n) == 1 || (m+n!=0  && m==n) )
        {
            System.out.println("YES");
        }
        else
        {
            System.out.println("NO");
        }
    }

}