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

public class Main implements Runnable {
    static StringTokenizer st;
    static BufferedReader br;
    static PrintWriter out;
    static Random rand;

    public static void main(String[] args) throws IOException {
    rand = new Random();
    br = new BufferedReader(new InputStreamReader(System.in));
    out = new PrintWriter(new OutputStreamWriter(System.out));
    new Main().run();
    out.flush();
    }

    String nline() {
    try {
        return br.readLine();
    } catch (Exception e) {
        return null;
    }
    }

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

    int ni() {
    return Integer.valueOf(ns());
    }

    long nl() {
    return Long.valueOf(ns());
    }

    double nd() {
    return Double.valueOf(ns());
    }

    public void run() {
    Solve();
    }

    void Solve() {
    int n = ni(), x1 = ni(), y1 = ni(), x2 = ni(), y2 = ni();
    int ans = 0.0;
    if ((x1 == 0 && x2 == 0) || (x1 == n && x2 == n)) {
        ans = abs(y1 - y2);
    } else if ((y1 == 0 && y2 == 0) || (y1 == n && y2 == n)) {
        ans = abs(x1 - x2);
    } else if ((x1 == 0 && x2 == n) || (x1 == n && x2 == 0)) {
        ans = min((n + y1 + y2), (n + (n - y1) + (n - y2)));
    } else if ((y1 == 0 && y2 == n) || (y1 == n && y2 == 0)) {
        ans = min((n + x1 + x2), (n + (n - x1) + (n - x2)));
    } else if (x1 == 0 && y2 == 0) {
        ans = y1 + x2;
    } else if (x2 == 0 && y1 == 0) {
        ans = y2 + x1;
    } else if (x1 == 0 && y2 == n) {
        ans = n - y1 + x2;
    } else if (x2 == 0 && y1 == n) {
        ans = n - y2 + x1;
    } else if (x1 == n && y2 == 0) {
        ans = y1 + n - x2;
    } else if (x2 == n && y1 == 0) {
        ans = y2 + n - x1;
    } else if (x1 == n && y2 == n) {
        ans = n - x2 + n - y1;
    } else if (x2 == n && y1 == n) {
        ans = n - x1 + n - y2;
    }

    out.println(ans);
    }

}


import java.util.Scanner;
public class Program
{
	public static void main(String[] args) {
	Scanner input= new Scanner(System.in);
	String str = input.next();
	int count=0;
	 for(int i=0 ; i<str.length(); i++){
	 for(int j=(i+1); j<str.length() ; j++){
	   if(str.charAt(i)== str.charAt(j)){
 str=str.substring(0,j)+str.substring(j);
 j--;
 count++;

	   }
		}
	   }
	   if ((str.length()-count) %2 ==0)
	   System.out.println("CHAT WITH HER!");
	else
	System.out.println("I GNORE HIM!");
	}
}


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

public class Parallelepiped {
	public static void main(String[] args) {
		MyScanner in = new MyScanner();

		int a1=in.nextInt(), a2=in.nextInt(), a3=in.nextInt();
		for(int i=0; i<10000; i++) {
			for(int j=0; j<10000; j++) {
				for(int k=0; k<10000; k++) {
					if(i*j==a1&&i*k==a2&&j*k==a3) {
						System.out.println(4*k+4*j+4*i);
						return;
					}
				}
			}
		}
	}

	static class MyScanner {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st;
		String next() {
			while(st==null||!st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception e) {}
			}
			return st.nextToken();
		}
		int nextInt() {
			return Integer.parseInt(next());
		}
	}
}


import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        System.out.println(Integer.toString(110, 15));
        Scanner r = new Scanner(System.in);

        String a = r.next();
        String b = r.next();

        int ai = Integer.parseInt(a);
        int bi = Integer.parseInt(b);

        int base = 2;

        for(int i = 0; i < a.length(); i++)
            base = Math.max(base, a.charAt(i)-'0'+1);
        for(int i = 0; i < b.length(); i++)
            base = Math.max(base, b.charAt(i)-'0'+1);

        System.out.println(Integer.toString(Integer.parseInt(a, base)+Integer.parseInt(b, base), base).length());

    }
}


package round240;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class B {
	InputStream is;
	PrintWriter out;
	String INPUT = "";

	void solve()
	{
		int n = ni(), K = ni();
		int mod = 1000000007;
		int[] dp = new int[n+1];
		Arrays.fill(dp, 1);
		dp[0] = 0;
		for(int i = 0;i < K-1;i++){
			for(int j = n;j >= 1;j--){
				for(int k = 2*j;k <= n;k+=j){
					dp[k] += dp[j];
					if(dp[k] >= mod)dp[k] -= mod;
				}
			}
		}
		long ret = 0;
		for(int j = 1;j <= n;j++){
			ret += dp[j];
		}
		out.println(ret%mod);
	}

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

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

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

	private byte[] inbuf = new byte[1024];
	private int lenbuf = 0, ptrbuf = 0;

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

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

	private double nd() { return Double.parseDouble(ns()); }
	private char nc() { return (char)skip(); }

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

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

	private char[][] nm(int n, int m)
	{
		char[][] map = new char[n][];
		for(int i = 0;i < n;i++)map[i] = ns(m);
		return map;
	}

	private int[] na(int n)
	{
		int[] a = new int[n];
		for(int i = 0;i < n;i++)a[i] = ni();
		return a;
	}

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

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

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

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
	private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}


// https://codeforces.com/contest/1174/submission/55043857 (rainboy)
import java.io.*;

public class CF1174E {
	static final int MD = 1000000007;
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int[] aa = new int[n + 1];
		for (int i = 1; i <= n; i++)
			aa[i] = i % 2 == 0 ? aa[i / 2] + 1 : 0;
		int k = 0;
		while (1 << k + 1 <= n)
			k++;
		int[] cnt = new int[k + 1];
		int[] cnt3 = new int[k + 1];
		for (int i = 1; i <= n; i++) {
			int a = aa[i];
			cnt[a]++;
			if (i % 3 == 0)
				cnt3[a]++;
		}
		long[][] dp = new long[n + 1][k + 1];
		dp[1][k] = 1;
		for (int i = 1; i < n; i++)
			for (int h = 0; h <= k; h++) {
				long x = dp[i][h];
				if (x != 0) {
					if (h > 0)
						dp[i + 1][h - 1] = (dp[i + 1][h - 1] + x * cnt[h - 1]) % MD;
					dp[i + 1][h] = (dp[i + 1][h] + x * (n / (1 << h) - i)) % MD;
				}
			}
		long ans = dp[n][0];
		if (3 << k - 1 <= n) {
			dp = new long[n + 1][k];
			long[][] dq = new long[n + 1][k];
			dq[1][k - 1] = 1;
			for (int i = 1; i < n; i++)
				for (int h = 0; h < k; h++) {
					long x = dq[i][h];
					if (x != 0) {
						if (h > 0)
							dq[i + 1][h - 1] = (dq[i + 1][h - 1] + x * cnt3[h - 1]) % MD;
						dq[i + 1][h] = (dq[i + 1][h] + x * (n / (3 << h) - i)) % MD;
						dp[i + 1][h] = (dp[i + 1][h] + x * (n / (1 << h) - n / (3 << h))) % MD;
					}
					x = dp[i][h];
					if (x != 0) {
						if (h > 0)
							dp[i + 1][h - 1] = (dp[i + 1][h - 1] + x * cnt[h - 1]) % MD;
						dp[i + 1][h] = (dp[i + 1][h] + x * (n / (1 << h) - i)) % MD;
					}
				}
			ans = (ans + dp[n][0]) % MD;
		}
		System.out.println(ans);
	}
}


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

   public class x1174E
   {
      static long MOD = 1000000007L;
      public static void main(String hi[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         dp = new long[N+1][20][2];
         for(int i=0; i <= N; i++)
            for(int a=0; a < 20; a++)
               Arrays.fill(dp[i][a], -1);
         for(int a=0; a < 20; a++)
            Arrays.fill(dp[0][a], 0);
         base(dp, N);
         cnt = new long[20][2];
         for(int curr=0; (1<<curr) <= N; curr++)
            for(int b=1; b <= 3; b+=2)
            {
               int temp = (1<<curr)*b;
               cnt[curr][Math.max(b-2, 0)] = N/temp;
            }
         System.out.println(dfs(N, 0, 0));
      }
      static long[][][] dp;
      static long[][] cnt;
      public static long dfs(int i, int a, int b)
      {
         if(dp[i][a][b] != -1)
            return dp[i][a][b];
         long res = 0L;
         if(cnt[a][b]-i >= 0)
            res = (dfs(i-1,a,b)*(cnt[a][b]-i+1+MOD))%MOD;
         if(a+1 < 20)
         {
            res += (dfs(i-1,a+1,b)*(cnt[a][b]-cnt[a+1][b]))%MOD;
            res %= MOD;
         }
         if(b == 0)
         {
            res += (dfs(i-1,a,1)*(cnt[a][0]-cnt[a][1]))%MOD;
            res %= MOD;
         }
         return dp[i][a][b] = res;
      }
      public static void base(long[][][] dp, int N)
      {
         int curr = 1;
         while((1<<curr) <= N)
            curr++;
         curr--;
         dp[1][curr][0] = 1L;
         int oth = 1<<(curr-1);
         oth *= 3;
         if(oth <= N)
            dp[1][curr-1][1] = 1L;
      }
   }


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.StringTokenizer;

public class TC
{
    static int N;
    static ArrayList<Integer>[] adjMat;
    static HashSet<Integer> p1, p2;

    static boolean verify()
    {
        boolean isDone=true;

        for( int i=1; i<=N; i++ )
        {
            HashSet<Integer> curr, other;

            if( p1.contains(i))
            {
                curr=p1;
                other=p2;
            }

            else
            {
                curr=p2;
                other=p1;
            }

            int cnt=0;

            for( int nbr:adjMat[i])
            {
                if( curr.contains(nbr))
                    cnt++;
            }

            if( cnt >=2 )
            {
                isDone=false;
                curr.remove(i);
                other.add(i);
            }

        }

        return isDone;
    }

    static void solve() throws IOException
    {
        p1=new HashSet();
        p2=new HashSet();

        for( int i=1; i<=N; i++ )
            p1.add(i);

        boolean isValid=false;

        while( !isValid )
        {
            isValid=verify();
        }

        BufferedWriter out=new BufferedWriter( new OutputStreamWriter( System.out ));

        for( int i=1; i<=N; i++ )
        {
            if( p1.contains(i))
                out.write("0");

            else
                out.write("1");

        }

        out.write("\n");
        out.close();

    }

    public static void main( String[] args ) throws IOException
    {
        BufferedReader br=new BufferedReader( new InputStreamReader( System.in ) );
        String s=br.readLine();
        StringTokenizer tok=new StringTokenizer( s );
        N=Integer.parseInt( tok.nextToken() );
        int m=Integer.parseInt( tok.nextToken() );
        adjMat=new ArrayList[N+1];
        for( int i=0; i<N+1; i++ )
            adjMat[i]=new ArrayList();
        while( m-- > 0 )
        {
            s=br.readLine();
            tok=new StringTokenizer( s );
            int a=Integer.parseInt( tok.nextToken() );
            int b=Integer.parseInt( tok.nextToken() );
            adjMat[a].add(b);
            adjMat[b].add(a);
        }
        solve();

    }
}


import java.util.Scanner;
public class BuyingAHouse {
	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();
		int m=scan.nextInt();
		int k=scan.nextInt();
		int num1=0,num2=0;
		int t[]=new int[n+1];
		for(int i=0;i<n;i++)
			t[i]=scan.nextInt();
		for(int i=m-1,j=m-1;i>=0 || j<n;i--,j++)
		{
			if(t[(i>=0)?i:0]==0 || t[(i>=0)?i:0]>k ) num1++;
			else break;
			if(t[(j<n)?j:n-1]==0 || t[(j<n)?j:n-1]>k ) num2++;
			else break;
		}
		System.out.println((num1<num2)?10*d1:10*d2);
	}
}


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

		if (position.equals("a1") || position.equals("a8") || position.equals("h1") || position.equals("h8")) {
			System.out.println("3");
		}
		else if (position.contains("a") || position.contains("h") || position.contains("1") || position.contains("8")) {
			System.out.println("5");
		}
		else {
			System.out.println("8");
		}
	}
}


import java.util.Scanner;

public class Elections {

	public static void main(String[] args) {
		Scanner f = new Scanner(System.in);
		int b = f.nextInt();
		int c = 0, sum = 0;
		for (int i = 0; i < b; i++) {
			int ai = f.nextInt();
			k = Math.max(c, ai);
			sum += ai;
		}
		System.out.println(Math.max(c, 2 * sum / b + 1));
	}
}
}


import java.io.*;
import java.math.*;
import java.security.KeyStore.Entry;
import java.util.*;

 public class Main1 {
	private InputStream is;
	private PrintWriter out;
	int time = 0, dp[][], DP[][], start[], parent[], end[], val[], black[], MOD = (int)(1e9+7), arr[], arr1[];
	int MAX = 10000000, N, K, p;
	ArrayList<Integer>[] amp, amp1;
	boolean b[], b1[];
	Pair prr[];
	char ch[][];
	HashSet<Integer> hs = new HashSet<>();

	public static void main(String[] args) throws Exception {
		new Thread(null, new Runnable() {
		public void run() {
			try {

		//new Main().soln();
		} catch (Exception e) {
				System.out.println(e);
			}
		}
	}, "1", 1 << 26).start();
		new Main().soln();
	}
	void solve() {
		long n = nl(), s = nl();
		long low = 1, high = n+1;
		long ans = high;
		while(low<=high){
			long mid = (high+low)/2;
			if((mid - getSum(mid))>=s){
				high = mid-1;
				ans = mid;
			}
			else{
				low = mid+1;
			}
		}
		System.out.println(Math.max(0, n-ans+1));
	}
	int getSum(long s){
		String str = Long.toString(s);
		int ans = 0;
		for(char ch : str.toCharArray()) ans += (ch-'0');
		return ans;
	}
	int recur(int x){
		//System.out.println(x);
		int ans = 0;
		b[x] = true;
		for(int i : amp[x]){
			if(!b[i]){
				b[i] = true;
				ans = Math.max(recur(i), ans);
				b[i] = false;
			}
		}
		return 1+ans;
	}
	int max = 0;
	int getParent(int x){
		//System.out.println(x+" "+parent[x]);
		if(parent[x]!=x){
			parent[x] = getParent(parent[x]);
		}
		return parent[x];
	}
	int bfs(int x){
		b[x] = true;
		Queue<Integer> q =  new LinkedList<>();
		q.add(x);
		while(!q.isEmpty()){
			int y = q.poll();
			for(int i : amp[y]){
				if(!b[i]){
					b[i] = true;
					val[i] = val[y]+1;
					max = Math.max(val[i], max);
					q.add(i);
				}
			}
		}
		return max;
	}
	class Pair implements Comparable<Pair>{
		int u, v, r;
		Pair(int u, int v){
			this.u = u;
			this.v = v;
		}public int hashCode() {
			return Objects.hash();
		}
		public boolean equals(Object o) {
			Pair other = (Pair) o;
			return ((u == other.u && v == other.v));// || (v == other.u && u == other.v));
		}
		public int compareTo(Pair other) {
			//return Integer.compare(other.r, r);
			return Long.compare(u, other.u) != 0 ? (Long.compare(u, other.u)) : (Long.compare(other.v,v));
		}
		public String toString() {
			return "[u=" + u + ", v=" + v + "]";
		}
	}
	int min(int x,int y){
		if(x<y) return x;
		return y;
	}
	int max(int x,int y){
		if(x>y) return x;
		return y;
	}
	void dfs(int x){
		b[x] = true;
		for(int i : amp[x]){
			if(!b[i]){
				dfs(i);
			}
		}
	}
	void buildGraph(int m){
		while(m-->0)
		{
			int x = ni()-1, y = ni()-1;
			amp[x].add(y);
			amp[y].add(x);
		}
	}
	long modInverse(long a, long mOD2){
        return  power(a, mOD2-2, mOD2);
	}
	long power(long x, long y, long m)
	{
		if (y == 0)
    return 1;
	long p = power(x, y/2, m) % m;
	p = (p * p) % m;

	return (y%2 == 0)? p : (x * p) % m;
	}
	boolean isPrime(int x){
		for(int i = 2;i*1L*i<=x;i++) if(x%i==0) return false;
		return true;
	}
	public long gcd(long a, long b){
		if(b==0) return a;
		return gcd(b,a%b);
	}
	void failFn(String str, int arr[]){
		int len = 0;
		arr[0] = 0;
		int i = 1;
		while(i<arr.length){
			if(str.charAt(i)==str.charAt(len)){
				arr[i++] = ++len;
				continue;
			}
			if(len == 0){
				arr[i] = len;
				i++;
				continue;
			}
			if(str.charAt(i)!=str.charAt(len)){
				len = arr[len-1];
			}
		}
	}
	static class ST1{
		int arr[], st[], size;
		ST1(int a[]){
			arr = a.clone();
			size = 10*arr.length;
			st = new int[size];
			build(0,arr.length-1,1);
		}
		void build(int ss, int se, int si){
			if(ss==se){
				st[si] = arr[ss];
				return;
			}
			int mid = (ss+se)/2;
			int val = 2*si;
			build(ss,mid,val); build(mid+1,se,val+1);
			st[si] = (st[val]+ st[val+1]);
		}
		int get(int ss, int se, int l, int r, int si){
			if(l>se || r<ss || l>r) return Integer.MAX_VALUE;
			if(l<=ss && r>=se) return st[si];
			int mid = (ss+se)/2;
			int val = 2*si;
			return (get(ss,mid,l,r,val)+ get(mid+1,se,l,r,val+1));
		}
	}
	static class ST{
		int arr[],lazy[],n;
		ST(int a){
			n = a;
			arr = new int[10*n];
			lazy = new int[10*n];
		}
		void up(int l,int r,int val){
			update(0,n-1,0,l,r,val);
		}
		void update(int l,int r,int c,int x,int y,int val){
			if(lazy[c]!=0){
				lazy[2*c+1]+=lazy[c];
				lazy[2*c+2]+=lazy[c];
				if(l==r)
					arr[c]+=lazy[c];
				lazy[c] = 0;
			}
			if(l>r||x>y||l>y||x>r)
				return;
			if(x<=l&&y>=r){
				lazy[c]+=val;
				return ;
			}
			int mid = l+r>>1;
			update(l,mid,2*c+1,x,y,val);
			update(mid+1,r,2*c+2,x,y,val);
			arr[c] = (arr[2*c+1]+ arr[2*c+2]);
		}
		int an(int ind){
			return ans(0,n-1,0,ind);
		}
		int ans(int l,int r,int c,int ind){
			if(lazy[c]!=0){
				lazy[2*c+1]+=lazy[c];
				lazy[2*c+2]+=lazy[c];
				if(l==r)
					arr[c]+=lazy[c];
				lazy[c] = 0;
			}
			if(l==r)
				return arr[c];
			int mid = l+r>>1;
			if(mid>=ind)
				return ans(l,mid,2*c+1,ind);
			return ans(mid+1,r,2*c+2,ind);
		}
	}
	public static class FenwickTree {

	    int[] array; // 1-indexed array, In this array We save cumulative information to perform efficient range queries and updates

	    public FenwickTree(int size) {
	        array = new int[size + 1];
	    }
	    public int rsq(int ind) {
	        assert ind > 0;
	        int sum = 0;
	        while (ind > 0) {
	            sum += array[ind];
	            //Extracting the portion up to the first significant one of the binary representation of 'ind' and decrementing ind by that number
	            ind -= ind & (-ind);
	        }
	        return sum;
	    }
	    public int rsq(int a, int b) {
	        assert b >= a && a > 0 && b > 0;
	        return rsq(b) - rsq(a - 1);
	    }
	    public void update(int ind, int value) {
	        assert ind > 0;
	        while (ind < array.length) {
	            array[ind] += value;
	            //Extracting the portion up to the first significant one of the binary representation of 'ind' and incrementing ind by that number
	            ind += ind & (-ind);
	        }
	    }
	    public int size() {
	        return array.length - 1;
	    }
	}
	public static int[] shuffle(int[] a, Random gen){
		for(int i = 0, n = a.length;i < n;i++)
		{
			int ind = gen.nextInt(n-i)+i;
			int d = a[i];
			a[i] = a[ind];
			a[ind] = d;
		}
	return a;
	}
	long power(long x, long y, int mod){
		long ans = 1;
		while(y>0){
			if(y%2==0){
				x = (x*x)%mod;
				y/=2;
			}
			else{
				ans = (x*ans)%mod;
				y--;
			}
		}
		return ans;
	}
	void soln() {
		is = System.in;
		out = new PrintWriter(System.out);
		long s = System.currentTimeMillis();
		solve();
		//out.close();
		out.flush();
		//tr(System.currentTimeMillis() - s + "ms");
	}

	// To Get Input
	// Some Buffer Methods
	private byte[] inbuf = new byte[1024];
	public int lenbuf = 0, ptrbuf = 0;

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

	private boolean isSpaceChar(int c) {
		return !(c >= 33 && c <= 126);
	}

	private int skip() {
		int b;
		while ((b = readByte()) != -1 && isSpaceChar(b))
			;
		return b;
	}

	private double nd() {
		return Double.parseDouble(ns());
	}

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

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

	private char[][] nm(int n, int m) {
		char[][] map = new char[n][];
		for (int i = 0; i < n; i++)
			map[i] = ns(m);
		return map;
	}

	private int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}

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

		while (true) {
			if (b >= '0' && b <= '9') {
				num = num * 10 + (b - '0');
			} else {
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

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

		while (true) {
			if (b >= '0' && b <= '9') {
				num = num * 10 + (b - '0');
			} else {
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private boolean oj = System.getProperty("ONLINE_JUDGE") != null;

	private void tr(Object... o) {
		if (!oj)
			System.out.println(Arrays.deepToString(o));
	}
}


import java.util.Scanner;
import java.util.stream.StreamSupport;

public class Lol {
    public static void main(String [] args)
    {
        int white = 0;
        int black = 0;
        boolean o = false;
        Scanner s = new Scanner(System.in);
        char[][] arr = new char[4][4];
        for(int i = 0; i < 4; i++)
        {
            for(int j = 0; j < 4; j++)
            {
                arr[i][j] = s.next().charAt(0);
            }
        }
        for(int i = 0; i < 3; i++)
        {
            for(int j = 0; j < 3; j++)
            {
                if(black >= 3 || white >= 3)
                {
                    System.out.println("YES");
                    o = true;
                    break;
                }
                black = 0; white = 0;
                if(arr[i][j] == '#')
                {
                    black++;
                }
                if(arr[i][j + 1] == '#')
                {
                    black++;
                }
                if(arr[i + 1][j] == '#')
                {
                    black++;
                }
                if(arr[i + 1][j + 1] == '#')
                {
                    black++;
                }
                if(arr[i][j] == '.')
                {
                    white++;
                }
                if(arr[i][j + 1] == '.')
                {
                    white++;
                }
                if(arr[i + 1][j] == '.')
                {
                    white++;
                }
                if(arr[i + 1][j + 1] == '.')
                {
                    white++;
                }
            }
            if(o == true)
            {
                break;
            }
        }
        if(o == false)
        {
            System.out.println("NO");
        }
    }
}


import java.util.*;
public class HelloWorld{

     public static void main(String []args){
        Scanner sc = new Scanner(System.in);
        int[] a;
        int a[4];
        double s=0;
       for(int i=0; i<4;i++)
       {
            a[i]=sc.nextInt();
       }
        {
           s+=a[i];
       }

        if(s%5==0){System.out.print((int)(s/5));} else {System.out.print("-1");}}
          }
}


import java.util.*;

public class InitialBet
{
	public static void main(String args[])
	{
		int sum=0;
		int[] a=new int[5];
		Scanner s=new Scanner(System.in);
		for(int i=0;i<5;i++)
		{
			a[i]=a.nextInt();
		}
		for(int i=0;i<5;i++)
		{
			sum=sum+a[i];
		}
		if(sum%5==0)
		{
			System.out.print(sum/5);
		}
		else
		{
			System.out.print("-1");
		}
	}
}


import java.util.*;
import java.util.Map.Entry;

public class D {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		long n = scan.nextInt();
		long k = scan.nextInt();
		long m = scan.nextInt();

		//long n = 5;
		//long k = 3;
		//long m = 1103;

		long[][] dp = new long[(int)m][(int)k];

		for (int i = 1; i<10; i++) {
			int ind = (int)(i%k);
			dp[0][ind] += 1;
			dp[0][ind] %= m;
		}

		long mult = 1;
		for (int i = 1; i<n; i++) {
			mult *= 10;
			mult %= k;
			for (int j = 1; j<10; j++) {
				long add = j*mult;
				add %= k;
				for (int a = 1; a<k; a++) {
					int ind = (int)((a+add)%k);
					dp[i][ind] += dp[i-1][a];
					dp[i][ind] %= m;
					for (int b = 2; b<=i; b++) {
						dp[i][ind] += dp[i-b][a];
						dp[i][ind] %= m;
					}
				}

				dp[i][(int)add]++;
			}
			//dp[i][0] += 9*dp[i-1][0];
			//long mult2 = 1;
			//for (int j = 1; j<=i; j++) {
			//	dp[i][0] += 9*mult2*dp[i-j][0];
			//	mult2*=10;
			//}
			//System.out.println(dp[i][0] + " " + dp[i][1] + " " + dp[i][2]);
		}
		//System.out.println();
		long tot = 0;
		long mult2 = 9;
		for (int i = (int)n-2; i>=0; i--) {
			//System.out.println(i + " " + dp[i][0] + " " + dp[i][0]%m);
			tot += dp[i][0]*mult2;
			tot %= m;
			mult2 *= 10;
			mult2 %= m;
		}
		tot += dp[(int)n-1][0];
		tot %= m;
		//System.out.println("\n" + tot);
		System.out.println(tot);
		//System.out.println();
		//test(5,3,1103);

		scan.close();
	}

	public static void test(int n, int k, int m) {

		int s = 1;
		int e = 10;
		for (int i = 1; i<n; i++) {
			s*=10;
			e*=10;
		}

		long tot = 0;

		int ten = e;
		for (int x = s; x<e; x++) {
			ten = e;
			int xx = x;
			//System.out.print(x + " ");
			boolean good = false;
			for (int i = 0; i<n; i++) {
				ten/=10;
				if (xx%k == 0) {
					good = true;
					break;
					//System.out.print(xx);
				} else {
					//for (int j = 0; j<n-i; j++)
						//System.out.print("-");
				}
				//System.out.print(" ");
				xx%=ten;
				if (xx == 0)
					break;
			}
			if (good) {
				//System.out.println(x);
				tot++;
			}

			//System.out.println();
		}
		System.out.println(tot);
	}
}


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

public class P1 {
	public static void main(String[] args) throws Exception{
		System.setIn(new FileInputStream("input.txt"));
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String line = reader.readLine();

		String[] data = line.split(" ");
		int n = Integer.parseInt(data[0]);
		int k = Integer.parseInt(data[1]);

		data = reader.readLine().split(" ");
		double average = 0;
		for(int i = 0; i < n; i++){
			int mark = Integer.parseInt(data[i]);
			average = average + mark;
		}

		double x = k-0.5;
		int result = (int) Math.ceil(2*(n*x-average));
		if(result < 0){
			result = 0;
		}
		System.out.println(result);
	}
}


package Java_1st;

import java.util.Scanner;
import java.lang.String;
public class Main
{
    private static float round_off(float num)
    {
        int digit_part = (int)num;
        float fraction_part = num - (float)digit_part;
        if(fraction_part < 0.5)
        {
            return (float)digit_part;
        }
        else
        {
            digit_part++;
            return (float)digit_part;
        }

    }

    public static void main(String[] args)
    {

        Scanner input = new Scanner(System.in);
        int n,k;
        n = input.nextInt();
        k = input.nextInt();
        if (n < 1 || n > 100 || k < 1 || k > 100 )
        {

        }
        else {
            float[] array = new float[n];
            boolean success_input = true;
            for (int i = 0; i < n; i++) {
                array[i] = input.nextFloat();
                if (array[i] < 1 || array[i] > 100 || array[i] > k) {
                    success_input = false;
                    break;
                }
            }
            if (success_input) {
                float sum = 0;
                float mark = 0;
                for (int i = 0; i < n; i++) {
                    sum += array[i];
                }
                mark = sum / n;
                int minimum = 0;
                while(round_off(mark)!=k)
                {
                    sum +=k;
                    minimum++;
                    mark = sum/(minimum+n);
                }
                System.out.println(minimum);

            }
        }
        }
    }


import java.util.*;

public class Chores {
	static Scanner scan = new Scanner(System.in);
	public static void main(String[] args) {
		int number = scan.nextInt();
		int time = scan.nextInt();
		int x = scan.nextInt();
		int s = 0;
		for(int i = 0; i<number-time; i++){
			s += reader.nextInt();
		}

		System.out.println(s+(time*x));
	}
}


package demo;

import java.util.Scanner;

public class DemoTranslation {
	public static int n, k, x;
	Scanner scan = new Scanner(System.in);
	public static int[] a = new int[1_000];

	public static void main(String[] args) {
		n = scan.nextInt();
		k = scan.nextInt();
		x = scan.nextInt();
		int sum = 0;
		for(int i = 0; i < n; i++) {
			a[i] = scan.nextInt();
			sum += a[i];
		}
		sum -= a[n - 1];
		sum += x;
		k--;
		int num = 1;
		while(k != 0) {
			if(a[n - 1 - num] <= x) {
				break;
			}
			sum -= a[n - 1 - num];
			sum += x;
			num++;
			k--;
		}
		System.out.println(sum);
	}

}


//Too slow

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

public class SportMafia {
    private static int[] factorials;
    private static int factorial(int N){
        return factorials[N];
    }
    private static void fill(int[] array){
        int current = 0;
        for (int i = 1; i < array.length; i++){
            array[i] = current + i;
            current = array[i];
        }
    }
    private static int works(int N, int deduct, int K){
        int put = factorial(N);
        put -= deduct;
        return Integer.compare(K, put);
    }
    private static int solve(int N, int K){
        int current = N / 2;
        int ate = N - current;
        int start = 0;
        int end = N;
        while (true){
            int result = works(current, ate, K);
            if (result == 0){
                return ate;
            } else if (result == -1){ //To high
                end = current - 1;
            } else {
                start = current + 1;
            }
            current = (start + end)/2;
            ate = N - current;
        }
    }
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer NK = new StringTokenizer(in.readLine());
        int N = Integer.parseInt(NK.nextToken());
        int K = Integer.parseInt(NK.nextToken());
        factorials = new int[N + 1];
        fill(factorials);
        System.out.println(solve(N, K));
    }
}


import java.util.*;
import java.io.PrintWriter;
import java.lang.Math;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;

public class In {
    static final int[] num_to_bits = new int[] { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4 };
    static final Scanner sc=new Scanner(System.in);

    public static void main(String[] args) {
        // int[] x={2,4,6};
        // long x = sc.nextLong();
        // while (x-- > 0) {
        // int n = sc.nextInt();
        // int[] a = new int[n];
        // for (int i = 0; i < a.length; i++) {
        // a[i] = sc.nextInt();
        // }
        // solve(n, a);
        // }
            cfr574B();

        sc.close();
    }
    public static void cfr574B() {
        int n=sc.nextInt(),k=sc.nextInt();
        int[] a=new int[n];
        if (n*(n+1)/2==k) {
            System.out.println(0);
            return;
        }
        for (int i = 0; i < n; i++) {
            if (i==0) {
                a[i]=1;
            }
            else{
                a[i]=a[i-1]+1+i;
            }
            if (a[i]-n+i+1==k) {
                System.out.println(n-i-1);
                break;
            }
        }

    }

    // static int[] v = new int[6 + 1];
    // static public int solve(int A, ArrayList<Integer> B) {

    // for (int i = 0; i < B.size(); i++) {
    // v[B.get(i).intValue()]=1;
    // }
    // int as=0;
    // Collections.sort(B);
    // int ans = 0;
    // for (int i = 0; i < B.size(); i++) {
    // if(!(i+1<B.size()))
    // continue;
    // if(i<A-1&&B.get(i+1)==1+i)
    // continue;
    // B.add(i+1);
    // v[B.get(i)] = 1;
    // ans+=solve(A,B)+1;
    // }
    // int a;
    // return as+1;
    // }

    // // static int findRank(String A) {
    // // long ans = 0;
    // // int i = 0;
    // // for (i = 0; i < A.length(); i++) {
    // // char a = A.charAt(i);
    // // long c = 0;
    // // for (int j = i; j < A.length(); j++) {
    // // if (a > A.charAt(j))
    // // c++;
    // // }
    // // Vector<Long> v = new Vector<Long>(52);
    // // for (int ii = 0; ii < 52; ii++) {
    // // v.add(0L);
    // // }
    // // for (int j = i; j < A.length(); j++) {
    // // int index;
    // // if (A.charAt(j) >= 'A' && A.charAt(j) <= 'Z') {
    // // index = (int) (A.charAt(j) - 'A');
    // // } else {
    // // index = (int) (A.charAt(j) - 'a' + 26);
    // // }
    // // Long obj = v.get(index);
    // // obj++;
    // // v.setElementAt(obj, index);
    // // }
    // // long d_fac = 1;
    // // for (int ii = 0; ii < 52; ii++) {
    // // long n4 = v.get(ii);
    // // d_fac *= factorial(n4);
    // // }
    // // d_fac = po(d_fac, mod - 2L, mod);
    // // if (c <= 0)
    // // continue;
    // // long n = A.length() - 1 - i;
    // // long n1 = c * factorial(n) % mod;
    // // ans += (n1 * d_fac) % mod;
    // // }
    // // return (int) ((ans + 1) % mod);
    // // }

    static long factorial(long n) {

        // single line to find factorial
        return (n == 1L || n == 0L) ? 1L : n * factorial(n - 1) % 1000003L;

    }

    public static int[] int2Array(int num) {
        return Integer.toString(num).chars().map(c -> c - '0').toArray();
    }

    static long modexp(long x, long y, long p) {
        long res = 1;
        x = x % p;
        while (y > 0) {
            if ((y & 1) == 1)
                res = (res * x) % p;
            y = y >> 1;
            x = (x * x) % p;
        }
        return res;
    }

    public static ArrayList<Integer> arr2arrlist(int arr[]) {
        ArrayList<Integer> array_list = new ArrayList<Integer>();

        // Using add() method to add elements in array_list
        for (int i = 0; i < arr.length; i++)
            array_list.add(new Integer(arr[i]));
        return array_list;
    }

    public static void sortbyColumn(int arr[][], int col) {
        // Using built-in sort function Arrays.sort
        Arrays.sort(arr, new Comparator<int[]>() {

            @Override
            // Compare values according to columns
            public int compare(final int[] entry1, final int[] entry2) {

                // To sort in descending order revert
                // the '>' Operator
                if (entry1[col] > entry2[col])
                    return 1;
                else
                    return -1;
            }
        }); // End of function call sort().
    }

    static int countSetBits(int n) {
        int count = 0;
        while (n > 0) {
            n &= (n - 1);
            count++;
        }
        return count;
    }

    static int countSetBitsRec(int num) {
        int nibble = 0;
        if (0 == num)
            return num_to_bits[0];

        // Find last nibble
        nibble = num & 0xf;

        // Use pre-stored values to find count
        // in last nibble plus recursively add
        // remaining nibbles.
        return num_to_bits[nibble] + countSetBitsRec(num >> 4);
    }
}

class Pair implements Comparable<Pair> {
    public final int index;
    public final int value;

    public Pair(int index, int value) {
        this.index = index;
        this.value = value;
    }

    @Override
    public int compareTo(Pair other) {
        // multiplied to -1 as the author need descending sort order
        return Integer.valueOf(this.value).compareTo(other.value);
    }
}


import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;
import java.util.Arrays;
import java.util.ArrayList;

public class project
{
    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

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

    static int binarySearch(long a[],int k,int l,int h){
        while(l<=h){
         int mid = (l+h)/2;
         if(a[mid]>=k) h=mid-1;
         if(a[mid]<k) l =mid+1;
        }
        return l;
    }

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

        FastReader sc = new FastReader();
        int n = sc.nextInt();
        int k = sc.nextInt();
        int add;
        int i;
        int sub;
        long sum[] = new long[n];

        for(i=1;i<=n;i++){
            sum[i-1]= (i*(i+1))/2;
        }
        int ans = binarySearch(sum, k,0,n-1);
        long ll = sum[ans];
        int l = (int)ll;
        add = ans+1;
        sub = l-k;
        if((add+sub) == n) System.out.print(sub);

        else{
            i = ans+1;
            while(i<n){
             ll = sum[i];
             l = (int)ll;
             add = i+1;
             sub = l-k;
             if((add+sub) == n) {System.out.print(sub);break;}
             i++;

            }
        }

    }

}


import java.util.Scanner;

public class KsushaArray {

	public static void main(String[] args) {
		Scanner scan =  new Scanner (System.in);
		int n= scan.nextInt();
		int k = scan.nextInt();
		int[] array = new int[n];
		int sum=0,j=1,eaten=0;
		for (int i=0;i<n;i++){
			if(sum<=k){
				array[i]=j;
				sum+=array[i];
				j++;
			}
			else {array[i]=-1;
				eaten++;
				sum+=array[i];
			}
		}
		System.out.println(eaten);

	}

}


package com.sh.codeforce;

import java.util.Scanner;

public class App {
    public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      long n=sc.nextInt();
      long a=sc.nextInt();
      long b=sc.nextInt();
      long c=sc.nextInt();
      long d=sc.nextInt();

      long m = 0;

      for(int checker=1;checker<=n;checker++){
    	  if(checker+b-c>=1 &&checker+b-c<=n && checker+a-d>=1 && checker+a-d<=n && checker+a+b-c-d>=1 && checker+a+b-c-d<=n){
  		    m++;
    	  }
  	  checker++;

      }
      System.out.println(n*m);
    }
}


/**
 * BaZ :D
 */
import java.util.*;
import java.io.*;
import static java.lang.Math.*;
public class ACMIND
{
    static FastReader scan;
    static PrintWriter pw;
    static long MOD = 1_000_000_007;
    static long INF = 1_000_000_000_000_000_000L;
    static long inf = 2_000_000_000;
    public static void main(String[] args) {
        new Thread(null,null,"BaZ",1<<25)
        {
            public void run()
            {
                try
                {
                    solve();
                }
                catch(Exception e)
                {
                    e.printStackTrace();
                    System.exit(1);
                }
            }
        }.start();
    }
    static int n, g[], t[], T;
    static int dp[][][];
    static void solve() throws IOException
    {
        scan = new FastReader();
        pw = new PrintWriter(System.out,true);
        StringBuilder fast = new StringBuilder();
        n = ni();
        T = ni();
        g = new int[n];
        t = new int[n];
        for(int i=0;i<n;++i) {
            t[i] = ni();
            g[i] = ni();
        }
        int MAX = (1<<n);
        dp = new int[MAX][T+1][4];
        for(int i=0;i<MAX;++i) {
            for(int j=0;j<=T;++j) {
                for(int k=0;k<4;++k) {
                    dp[i][j][k] = -1;
                }
            }
        }
        pl(f((1<<n)-1, T, 0));
        pw.flush();
        pw.close();
    }

    static int f(int mask, int left, int prev) {
        if(left==0) {
            return 1;
        }
        if(dp[mask][left][prev]!=-1) {
            return dp[mask][left][prev];
        }
        int cnt = 0;
        for(int i=0;i<n;++i) {
            if((mask&(1<<i))!=0) {
                if(g[i]!=prev && left>=t[i]) {
                    cnt+=f(mask^(1<<i), left - t[i], g[i]);
                    if(cnt>=MOD) {
                        cnt-=MOD;
                    }
                }
            }
        }
        return dp[mask][left][prev] = cnt;
    }
    static int ni() throws IOException
    {
        return scan.nextInt();
    }
    static long nl() throws IOException
    {
        return scan.nextLong();
    }
    static double nd() throws IOException
    {
        return scan.nextDouble();
    }
    static void pl()
    {
        pw.println();
    }
    static void p(Object o)
    {
        pw.print(o+" ");
    }
    static void pl(Object o)
    {
        pw.println(o);
    }
    static void psb(StringBuilder sb)
    {
        pw.print(sb);
    }
    static void pa(String arrayName, Object arr[])
    {
        pl(arrayName+" : ");
        for(Object o : arr)
            p(o);
        pl();
    }
    static void pa(String arrayName, int arr[])
    {
        pl(arrayName+" : ");
        for(int o : arr)
            p(o);
        pl();
    }
    static void pa(String arrayName, long arr[])
    {
        pl(arrayName+" : ");
        for(long o : arr)
            p(o);
        pl();
    }
    static void pa(String arrayName, double arr[])
    {
        pl(arrayName+" : ");
        for(double o : arr)
            p(o);
        pl();
    }
    static void pa(String arrayName, char arr[])
    {
        pl(arrayName+" : ");
        for(char o : arr)
            p(o);
        pl();
    }
    static void pa(String listName, List list)
    {
        pl(listName+" : ");
        for(Object o : list)
            p(o);
        pl();
    }
    static void pa(String arrayName, Object[][] arr) {
        pl(arrayName+" : ");
        for(int i=0;i<arr.length;++i) {
            for(Object o : arr[i])
                p(o);
            pl();
        }
    }
    static void pa(String arrayName, int[][] arr) {
        pl(arrayName+" : ");
        for(int i=0;i<arr.length;++i) {
            for(int o : arr[i])
                p(o);
            pl();
        }
    }
    static void pa(String arrayName, long[][] arr) {
        pl(arrayName+" : ");
        for(int i=0;i<arr.length;++i) {
            for(long o : arr[i])
                p(o);
            pl();
        }
    }
    static void pa(String arrayName, char[][] arr) {
        pl(arrayName+" : ");
        for(int i=0;i<arr.length;++i) {
            for(char o : arr[i])
                p(o);
            pl();
        }
    }
    static void pa(String arrayName, double[][] arr) {
        pl(arrayName+" : ");
        for(int i=0;i<arr.length;++i) {
            for(double o : arr[i])
                p(o);
            pl();
        }
    }
    static class FastReader {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

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

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

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

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

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

        public double nextDouble() throws IOException {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ') c = read();
            boolean neg = (c == '-');
            if (neg) c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (c == '.') while ((c = read()) >= '0' && c <= '9') ret += (c - '0') / (div *= 10);
            if (neg) return -ret;
            return ret;
        }

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

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

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


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

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

    static class G1PlaylistForPolycarpEasyVersion {
        public void solve(int testNumber, InputReader sc, PrintWriter out) {
            int n = sc.nextInt();
            int T = sc.nextInt();

            long mod = (long) 1e9 + 7;

            long dp[][][] = new long[1 << n][226][3];

            int t[] = new int[n];
            int g[] = new int[n];
            for (int i = 0; i < n; ++i) {
                t[i] = sc.nextInt();
                g[i] = sc.nextInt() - 1;
                dp[1 << i][t[i]][g[i]] = 1L;
            }

            for (int i = 0; i < (1 << n); ++i) {
                for (int j = 0; j < n; ++j) {
                    if ((i >> j & 1) == 1) {
                        int newMask = i ^ (1 << j);

                        for (int k = t[j]; k <= T; ++k) {
                            for (int l = 0; l < 3; ++l) {
                                if (l == g[j])
                                    continue;

                                dp[i][k][g[j]] = (dp[i][k][g[j]] + dp[newMask][k - t[j]][l]) % mod;
                            }
                        }
                    }
                }
            }

            long ans = 0;
            for (int i = 0; i < (1 << n); ++i) {
                for (int j = 0; j < 3; ++j) {
                    ans += dp[i][T][j];
                }
            }

            ans %= mod;
            out.print(ans);
        }

    }

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

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

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

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

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

        public int nextInt() {
            int c = read();

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

            int sgn = 1;

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

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

            return res * sgn;
        }

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

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

        }

    }
}


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

public class G_PlaylistForPolycarp {

	static final int mod = 1000000007;

	static int dp[][][];

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

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));

		String[] dat = br.readLine().split(" ");

		int n = Integer.parseInt(dat[0]);
		int T = Integer.parseInt(dat[1]);

		int [] st = new int[n];
		byte [] sg = new byte [n];

		dp = new int[T + 1][1 << (n + 1)][4];

		for (int i = 0; i <= T; i++) {
			for (int j = 0; j < 1 << (n + 1); j++) {
				for (int k = 0; k < 4; k++) {
					dp[i][j][k] = -1;
				}
			}
		}

		for (int i = 0; i < n; i++) {
			dat = br.readLine().split(" ");
			st[i] = Integer.parseInt(dat[0]);
			sg[i] = Byte.parseByte(dat[1]);
		}

		long count = recur(0, 0, st, sg, T, 0);

		bw.write(count + "\n");

		bw.close();

	}

	private static int recur(int time, int visited, int[] st, byte[] sg, int T, int last) {

		int count = 0;

		if (dp[time][visited][last] != -1) {
			return dp[time][visited][last];
		}

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

			if ((visited & (1 << i)) == 0 && sg[i] != last) {

				if (time + st[i] == T) {
					count += 1;
				} else if (time + st[i] < T) {
					int visitedc = visited | (1 << i);
					count += recur(time + st[i], visitedc, st, sg, T, sg[i]);
					if (count > mod) {
						count = count % mod;
					}
				}

			}

		}

		return dp[time][visited][last] = count % mod;
	}

}


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

   public class x1185G1
   {
      static long MOD = 1000000007L;
      public static void main(String args[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         int T = Integer.parseInt(st.nextToken());
         Song[] arr = new Song[N];
         for(int i=0; i < N; i++)
         {
            st = new StringTokenizer(infile.readLine());
            int a = Integer.parseInt(st.nextToken());
            int b = Integer.parseInt(st.nextToken())-1;
            arr[i] = new Song(a, b);
         }
         //bitmask
         long[][][] dp = new long[1 << N][T+1][3];
         Arrays.fill(dp[0][0], 1L);
         for(int mask=0; mask < dp.length; mask++)
         {
            //int cnt = Integer.bitCount(mask);
            for(int i=0; i < N; i++)
               if((mask & (1 << i)) == 0)
               {
                  Song c = arr[i];
                  //continue all dp if mask == 0
                  if(mask == 0 && c.t <= T)
                  {
                     dp[mask|(1 << i)][c.t][c.g]++;
                     dp[mask|(1 << i)][c.t][c.g] %= MOD;
                  }
                  //continue dp if not same genre
                  else
                  {
                     for(int gen=0; gen < 3; gen++)
                        if(gen != c.g)
                        {
                           for(int t=0; t <= T; t++)
                              if(dp[mask][t][gen] > 0 && t+c.t <= T)
                              {
                                 dp[mask|(1 << i)][t+c.t][c.g] += dp[mask][t][gen];
                                 dp[mask|(1 << i)][t+c.t][c.g] %= MOD;
                              }
                        }
                        //optimize?
                  }
               }
         }
         long res = 0L;
         for(int mask=1; mask < dp.length; mask++)
            for(int i=0; i < 3; i++)
               res = (res+dp[mask][T][i])%MOD;
         System.out.println(res);
      }
   }
   class Song
   {
      public int t;
      public int g;

      public Song(int a, int b)
      {
         t = a;
         g = b;
      }
   }
   //cheerios are good for your heart, but are they good for your brain?


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.FilterInputStream;
import java.io.BufferedInputStream;
import java.io.InputStream;

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

    static class G1playlist {
        int mod = 1000000007;

        public void solve(int testNumber, ScanReader in, PrintWriter out) {
            int n = in.scanInt();
            int T = in.scanInt();
            int[][] song = new int[n][2];
            for (int i = 0; i < n; i++) {
                song[i][0] = in.scanInt();
                song[i][1] = in.scanInt();
            }
            int[][][] dp = new int[T + 1][(1 << n)][4];
            dp[0][0][0] = 1;
            for (int t = 0; t <= T; t++) {
                for (int i = 0; i < (1 << n); i++) {
                    for (int j = 0; j < 4; j++) {
                        if (dp[t][i][j] == 0) continue;
                        for (int k = 0; k < n; k++) {
                            if (((1 << k) & i) == 0 && t + song[k][0] <= T && song[k][1] != j)
                                dp[t + song[k][0]][(1 << k) | i][song[k][1]] = (dp[t + song[k][0]][(1 << k) | i][song[k][1]] + dp[t][i][j]) % mod;
                        }
                    }
                }
            }
            long ans = 0;
            for (int i = 0; i < (1 << n); i++) {
                for (int j = 0; j < 4; j++) {
                    ans = (ans + dp[T][i][j]) % mod;
                }
            }
            out.println(ans);
        }

    }

    static class ScanReader {
        private byte[] buf = new byte[4 * 1024];
        private int index;
        private BufferedInputStream in;
        private int total;

        public ScanReader(InputStream inputStream) {
            in = new BufferedInputStream(inputStream);
        }

        private int scan() {
            if (index >= total) {
                index = 0;
                try {
                    total = in.read(buf);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (total <= 0) return -1;
            }
            return buf[index++];
        }

        public int scanInt() {
            int integer = 0;
            int n = scan();
            while (isWhiteSpace(n)) n = scan();
            int neg = 1;
            if (n == '-') {
                neg = -1;
                n = scan();
            }
            while (!isWhiteSpace(n)) {
                if (n >= '0' && n <= '9') {
                    integer *= 10;
                    integer += n - '0';
                    n = scan();
                }
            }
            return neg * integer;
        }

        private boolean isWhiteSpace(int n) {
            if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1) return true;
            else return false;
        }

    }
}


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

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

    static class G1PlaylistForPolycarpEasyVersion {
        final long mod = 1000000007;
        PrintWriter out;
        InputReader in;
        int n;
        int time;
        int[][] arr;
        long[][][] dp;

        long go(int mask, int t, int last) {
            if (t > time)
                return 0;
            if (t == time) {
                return 1l;
            }
            if (mask == (1 << n) - 1)
                return 0;
            if (dp[mask][t][last] != -1)
                return dp[mask][t][last];
            long cnt = 0;
            int i = 0, j = 0;
            for (i = 0; i < n; i++) {
                if ((mask & (1 << i)) == 0 && arr[i][1] != last) {
                    cnt += go(mask | (1 << i), t + arr[i][0], arr[i][1]);
                    cnt %= mod;

                }
            }
            dp[mask][t][last] = cnt;
            return cnt;
        }

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            this.out = out;
            this.in = in;
            n = ni();
            time = ni();
            arr = new int[n][2];
            int i = 0;
            for (i = 0; i < n; i++) {
                arr[i][0] = ni();
                arr[i][1] = ni() - 1;
            }
            dp = new long[1 << n][time + 1][3];
            for (i = 0; i < 1 << n; i++) {
                for (int j = 0; j <= time; j++)
                    Arrays.fill(dp[i][j], -1);
            }
            long ans = (((go(0, 0, 0) + go(0, 0, 1)) % mod + go(0, 0, 2)) % mod);
            ans *= modPow(2, mod - 2);
            ans %= mod;
            pn(ans);
        }

        int ni() {
            return in.nextInt();
        }

        void pn(Object o) {
            out.println(o);
        }

        long modPow(long a, long p) {
            long o = 1;
            while (p > 0) {
                if ((p & 1) == 1) o = mul(o, a);
                a = mul(a, a);
                p >>= 1;
            }
            return o;
        }

        long mul(long a, long b) {
            if (a >= mod) a %= mod;
            if (b >= mod) b %= mod;
            a *= b;
            if (a >= mod) a %= mod;
            return a;
        }

    }

    static 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 UnknownError();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new UnknownError();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

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

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

            return res.toString();
        }

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

    }
}


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

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

    private static class Solver {
        private void solve(InputReader inp, PrintWriter out) {
            int n = inp.nextInt(), t = inp.nextInt();
            int[][][] dp = new int[t+1][2 << n][3];
            long MOD = 1000000007;
            int[][] tracks = new int[n][2];
            for (int i = 0; i < n; i++) {
                tracks[i][0] = inp.nextInt();
                tracks[i][1] = inp.nextInt() - 1;
            }
            for (int i = 1; i <= t; i++) {
                for (int j = 0; j < n; j++) {
                    int time = tracks[j][0];
                    int genre = tracks[j][1];

                    if (i - time < 0) continue;
                    if (i - time == 0) {
                        dp[i][1 << j][genre]++;
                        continue;
                    }

                    for (int mask = 0; mask < (2 << n); mask++) {
                        if ((mask & (1 << j)) == 0) {
                            for (int g = 0; g < 3; g++) {
                                if (g == genre) continue;
                                dp[i][mask | (1 << j)][genre] += dp[i - time][mask][g];
                                dp[i][mask | (1 << j)][genre] %= MOD;
                            }
                        }
                    }

                }
            }

            long res = 0;
            for (int mask = 0; mask < (2 << n); mask++) {
                for (int g = 0; g < 3; g++) {
                    res = (res + dp[t][mask][g]) % MOD;
                }
            }
            out.print(res);

        }
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

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

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

        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
    }
}


import java.io.*;
import java.text.*;
import java.util.*;
import java.math.*;
public class G1 {
	public static void main(String[] args) throws Exception {
		new G1().run();
    }
    long MOD = 1_000_000_007;
	public void run() throws Exception {
		FastScanner f = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);
        int n = f.nextInt(), t = f.nextInt();
        long[][][] dp = new long[1 << n][t+1][3];
        int[] tarr = new int[n];
        int[] garr = new int[n];
        for(int i = 0; i < n; i++) {
            tarr[i] = f.nextInt();
            garr[i] = f.nextInt()-1;
            if(tarr[i] <= t) dp[1 << i][tarr[i]][garr[i]] = 1;
        }

        for(int i = 0; i < dp.length; i++) {
            for(int j = 0; j <= t; j++) {
                for(int k = 0; k < 3; k++) {
                    if(dp[i][j][k] == 0) continue;
                    for(int bi = 0; bi < n; bi++)
                        if(tarr[bi] + j <= t && (i & 1 << bi) == 0 && garr[bi] != k) {
                                    dp[i | 1 << bi][tarr[bi] + j][garr[bi]] =
                                        (dp[i | 1 << bi][tarr[bi] + j][garr[bi]] + dp[i][j][k]) % MOD;
                        }
                }

            }
        }
        long ans = 0;
        for(int i = 0; i < dp.length; i++)
            for(int j = 0; j < 3; j++)
            ans = (ans + dp[i][t][j]) % MOD;
        out.println(ans);
        out.flush();
	}
    static class FastScanner {
        public BufferedReader reader;
        public StringTokenizer tokenizer;
        public FastScanner() {
            reader = new BufferedReader(new InputStreamReader(System.in), 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());
        }
        public double nextDouble() {
        	return Double.parseDouble(next());
        }
        public String nextLine() {
        	try {
        		return reader.readLine();
        	} catch(IOException e) {
        		throw new RuntimeException(e);
        	}
        }
    }
}


package vanilla;

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

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

        Solver solver = new Solver();
        solver.solve(in, out);
        out.close();
    }
    static class Solver {
        void solve(Scanner in, PrintWriter out) {

            int n = in.nextInt();

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

            for (int i = 0; i < n; i++) {
                piles.add(in.nextInt());
            }

            Collections.sort(piles);

            if (piles.get(0).equals(piles.get(n/2))) {
                out.println("Bob");
            } else {
                out.println("Alice");
            }

        }
    }
}


import java.util.Scanner;

public class CF919B
{
	public static void main(String[] args)
	{
		CF919B task = new CF919B();
            Problem solver = task.new Problem();
            Scanner in = new Scanner(System.in);

            System.out.println(solver.solve(in.nextInt()));
	}

	public class Problem
	{
		public Problem()
		{

		}

	      public int solve(int k)
	      {
	            int ans = 0;

	            int[] knums = new int[100000000];

	            for(int i = 0, j = 0; i < knums.length; i++)
	            {
	                  int sumofn = sum(i);
	                  if(sumofn == 10)
	                  {
	                       knums[j] = i;
	                       j++;
	                  }
	            }
	            ans = knums[k - 1];

	            return ans;
	      }

	      private int sum(int n)
	      {
	            int ans = 0;

	            String str = Integer.toString(n);
	            char[] strarr = str.toCharArray();
                  for(int i = 0; i < strarr.length; i++)
                  {
                        ans = ans + (Integer.valueOf(strarr[i]) - 48);
                  }

	            return ans;
	      }
	}
}


import java.util.*;

public class Solution
{
    static long ways(int pos , int n)
    {
        if(pos >= n)
        return 1;

        if(dp[pos] != -1)
        return dp[pos];

        dp[pos] = (ways(pos + 1 , n) + ways(pos + 2 , n))%1000000007;
        return dp[pos];
    }
    public static void main(String []args)
    {
       Scanner sc = new Scanner(System.in);
       int n = sc.nextInt();
       dp = new long[n];
       for(int i = 0 ; i < n ; i++)
       {
           dp[i] = -1;
       }
       System.out.println(ways(0 , n) % 1000000007);
    }
}


import java.util.*;

public class Problem0209a
{
    public static void main(String[] args)
    {
        int mod = 1000000007;
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] dp = new long[n + 1];
        dp[0] = 0;
        dp[1] = 1;
        dp[2] = 2;
        if(n == 1)
        {
            System.out.println(1);
        }
        else if (n == 2)
        {
            System.out.println(2);
        }
        else {
            for (int i = 3; i <= n; i++)
            {
                dp[i] = (dp[i - 2] + dp[i - 1]) % mod;
            }
            long sum = 0;
            for (int i = 0; i < n; i++)
            {
                sum = (sum + dp[i + 1]) % mod;
            }
            System.out.println(sum);
        }
    }
}


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

public class BracketSubstring_CF1015F {

	static String s;
	static int len;
	static int sub;

	static int memo[][][][];
	static final int MOD = (int) 1e9 + 7;

	static int fail[];
	static char[] pat;

	static void pattern() {
		int len = pat.length;
		fail = new int[len];
		fail[0] = 0;
		int k = 0;
		for (int i = 1; i < len; i++) {
			while (k > 0 && pat[i] != pat[k])
				k = fail[k - 1];

			if (pat[i] == pat[k])
				fail[i] = ++k;
			else
				fail[i] = k;
		}
	}

	static int dp(int i, int count, int commpr, int used) {

		if (i == len) {
			return count == 0 && used == 1 ? 1 : 0;
		}

		if (count < 0)
			return 0;

		if (memo[i][count][commpr][used] != -1) {
			return memo[i][count][commpr][used];
		}
		int commpr1 = commpr;
		int newused1 = used;
		if (used == 0) {
			while (commpr1 > 0 && pat[commpr1] != '(')
				commpr1 = fail[commpr1 - 1];
			if (pat[commpr1] == '(')
				commpr1++;
			if (commpr1 == sub) {
				newused1 = 1;
				commpr1 = 0;

			}
		}
		int commpr2 = commpr;
		int newused2 = used;
		if (used == 0) {
			while (commpr2 > 0 && pat[commpr2] != ')')
				commpr2 = fail[commpr2 - 1];

			if (pat[commpr2] == ')')
				commpr2++;
			if (commpr2 == sub) {
				newused2 = 1;
				commpr2 = 0;
			}
		}

		int result = dp(i + 1, count + 1, commpr1, newused1);
		result += dp(i + 1, count - 1, commpr2, newused2);

		return memo[i][count][commpr][used] = result % MOD;

	}

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

		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		len = 2 * sc.nextInt();
		s = sc.next();
		sub = s.length();
		pat = s.toCharArray();
		memo = new int[len][len][sub][2];
		pattern();
		for (int i = 0; i < len; i++) {
			for (int j = 0; j < len; j++) {
				for (int k = 0; k < sub; k++)
					Arrays.fill(memo[i][j][k], -1);
			}
		}
		out.println(dp(0, 0, 0, 0));
		out.flush();
		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();
		}

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

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

	}

}


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

public class Main {

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

        new Main().go();
    }

    PrintWriter out;
    Reader in;
    BufferedReader br;

    Main() throws IOException {

        try {

            //br = new BufferedReader( new FileReader("input.txt") );
            //in = new Reader("input.txt");
            in = new Reader("input.txt");
            out = new PrintWriter( new BufferedWriter(new FileWriter("output.txt")) );
        }
        catch (Exception e) {

            //br = new BufferedReader( new InputStreamReader( System.in ) );
            in = new Reader();
            out = new PrintWriter( new BufferedWriter(new OutputStreamWriter(System.out)) );
        }
    }

    void go() throws Exception {

        //int t = in.nextInt();
        int t = 1;
        while (t > 0) {
            solve();
            t--;
        }

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

    int inf = 2000000000;
    int mod = 1000000007;
    double eps = 0.000000001;

    int n;
    int m;

    ArrayList<Pair>[] g;
    String s;
    int[] maxPref = new int[200];
    void solve() throws IOException {
        n = in.nextInt();
        s = in.nextLine();

        StringBuilder sb = new StringBuilder();
        sb.append(s.charAt(0));
        for (int i = 1; i < s.length(); i++) {
            char br = '(';
            if (s.charAt(i) == '(') br = ')';
            String t = sb.toString() + br;
            for (int j = 1; j < t.length(); j++) {
                boolean ok = true;
                int pos = 0;
                for (int k = j; k < t.length(); k++) {
                    ok &= s.charAt(pos) == t.charAt(k);
                    pos++;
                }
                if (ok) {
                    maxPref[i] = t.length() - j;
                    break;
                }
            }
            sb.append(s.charAt(i));
        }

        out.println(f(0, 0,0));
    }

    int cnt(int start, String sub, int n) {
        int[][] dp = new int[n][n];
        boolean[][] used = new boolean[n][n];
        for (int i = 0; i < n; i++) {
            boolean any = i < start || i >= start + sub.length();
            for (int j = 0; j <= n / 2; j++) {
                if (i == 0) {
                    if (any || sub.charAt(0) == '(') {
                        dp[0][1] = 1;
                        used[0][1] = true;
                    }
                    continue;
                }

                if (any || sub.charAt(i - start) == '(') {
                    if (used[i - 1][j]) {
                        dp[i][j + 1] = (dp[i][j + 1] + dp[i - 1][j]) % mod;
                        used[i][j + 1] = true;
                    }
                }

                if (any || sub.charAt(i - start) == ')') {
                    if (j > 0 && used[i - 1][j]) {
                        dp[i][j - 1] = (dp[i][j - 1] + dp[i - 1][j]) % mod;
                        used[i][j - 1] = true;
                    }
                }
            }
        }
        return dp[n - 1][0];
    }

    int[][][] dp = new int[200][101][201];
    boolean[][][] used = new boolean[200][101][201];
    int f(int pos, int balance, int pref) {

        if (balance < 0)
            return 0;

        if (pos == n * 2) {
            return balance == 0 && pref == s.length() ? 1 : 0;
        }

        if (used[pos][balance][pref])
            return dp[pos][balance][pref];

        int res = 0;
        if (pref == s.length()) {
            res = f(pos + 1, balance + 1, pref)
                    + f(pos + 1, balance - 1, pref);
        } else {
            if (s.charAt(pref) == '(') {
                res += f(pos + 1, balance + 1, pref + 1);
                res += f(pos + 1, balance - 1, maxPref[pref]);
            }
            else {
                res += f(pos + 1, balance - 1, pref + 1);
                res += f(pos + 1, balance + 1, maxPref[pref]);
            }
        }

        dp[pos][balance][pref] = res % mod;
        used[pos][balance][pref] = true;
        return dp[pos][balance][pref];
    }

    class Pair implements Comparable<Pair>{

        int a;
        int b;

        Pair(int a, int b) {

            this.a = a;
            this.b = b;
        }

        public int compareTo(Pair p) {
            if (a != p.a)
                return Integer.compare(a, p.a);
            else
                return Integer.compare(b, p.b);
        }
    }

    class Item {

        int a;
        int b;
        int c;

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

    }

    class Reader {

        BufferedReader  br;
        StringTokenizer tok;

        Reader(String file) throws IOException {
            br = new BufferedReader( new FileReader(file) );
        }

        Reader() throws IOException {
            br = new BufferedReader( new InputStreamReader(System.in) );
        }

        String next() throws IOException {

            while (tok == null || !tok.hasMoreElements())
                tok = new StringTokenizer(br.readLine());
            return tok.nextToken();
        }

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

        long nextLong() throws NumberFormatException, IOException {
            return Long.valueOf(next());
        }

        double nextDouble() throws NumberFormatException, IOException {
            return Double.valueOf(next());
        }

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

    }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

}


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

public class GFG
{
static int divCount(int n)
{
    boolean hash[] = new boolean[n + 1];
    Arrays.fill(hash, true);
    for (int p = 2; p * p < n; p++)
        if (hash[p] == true)
            for (int i = p * 2; i < n; i += p)
                hash[i] = false;

    int total = 1;
    for (int p = 2; p <= n; p++)
    {
        if (hash[p])
        {
            int count = 0;
            if (n % p == 0)
            {
                while (n % p == 0)
                {
                    n = n / p;
                    count++;
                }
                total = total * (count + 1);
            }
        }
    }
    return total;
}

// Driver Code
public static void main(String[] args)
{
    Scanner in=new Scanner(System.in);
    int n =in.nextInt();
    System.out.print(divCount(n));
}
}


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

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

/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		Scanner input = new Scanner(System.in);
		 int[][] arr = new int[5][5];

        for(int i =0;i<5;i++){
            for(int j=0;j<5;j++){
                arr[i][j]=input.nextInt();
            }
        }
        int count = 0;

        for(int i =0;i<5;i++){
            for(int j=0;j<5;j++){
                if(arr[i][j]==1){

                    while(j!=2 || i!=2){
                    if(i<2){
                        i+=1;
                        count++;
                    } if(i>2){
                        i--;
                        count++;
                    }
                    if(j<2){
                        j+=1;
                        count++;
                    }
                    if(j>2){
                        j--;
                        count++;

                    }
                    }

                }
            }
        }

        System.out.println(count);

	}
}


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

public class Main {

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

		int n = Integer.parseInt(br.readLine());
		String s = br.readLine();
		while(s.startsWith("0 "))
			s = s.substring(2);
		while(s.endsWith(" 0"))
			s = s.substring(0, s.length()-2);
		String[] l = s.split(" ");
		int c = 0;
		int res = 1;
		for(int i=0;i<n;i++){
			if(l[i].equals("1")){
				res*=(c+1);
				c = 0;
			} else {
				c++;
			}
		}
		pw.println(res);

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


import java.util.Scanner;

public class CodeForces{

    public static void main(String[] args){
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int[] money = new int[5];
        money[0] = 1;
        money[1] = 5;
        money[2] = 10;
        money[3] = 20;
        money[4] = 100;

        int[] dyn = new int[n];
        dyn[0] = 1;

        for(int i=1; i<dyn.length; i++){
            for(int j=money.length-1; j>=0; j--){
                if(i+1-money[j]>=0){
                    if(i+1-money[j]==0){
                        dyn[i] = 1;
                        break;
                    }
                    else{
                        dyn[i] = dyn[i-money[j]]+1;
                        break;
                    }
                }
            }
        }
        System.out.println(dyn[n-1]);
    }
}


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

public class R439_C {
	FastScanner in;
	PrintWriter out;

	static long reg = 998244353;
	static long a[][], c[][];

	public void solve() {
		int A = in.nextInt();
		int B = in.nextInt();
		int C = in.nextInt();
		int n = 5001;

		long fact[] = new long[n];
		fact[0] = 1;
		for (int i = 1; i < n; i++) {
			fact[i] = (long) (i) * fact[i - 1];
			fact[i] %= reg;
		}

		a = new long[n][n];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j <= i; j++) {
				a[i][j] = fact[i] / fact[i - j];
				a[i][j] %= reg;
			}
		}

		c = new long[n][n];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j <= i; j++) {
				c[i][j] = fact[i] / fact[i - j] / fact[j];
				c[i][j] %= reg;
			}
		}

		long res = 1;

		res *= f(Math.min(A, B), Math.max(A, B));
		res %= reg;
		res *= f(Math.min(A, C), Math.max(A, C));
		res %= reg;
		res *= f(Math.min(C, B), Math.max(C, B));
		res %= reg;

		out.println(res);
	}

	public long f(int x, int y) {
		long res = 0;
		for (int i = x; i > 0; i--) {
			res += (a[x][i] * c[y][i]);
			res %= reg;
		}
		return res + 1;
	}

	public void run() {
		in = new FastScanner();
		out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		solve();
		out.close();
	}

	class FastScanner {
		StringTokenizer st;
		BufferedReader br;

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

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				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());
		}
	}

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


import java.io.*;
import java.math.BigInteger;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.LongStream;

public class JavaPuzzler {

    //Scanner sc;
    private FastScanner sc;
    private PrintWriter out;

    private class FastScanner {

        BufferedReader br;
        StringTokenizer st;

        FastScanner(File f) {
            try {
                br = new BufferedReader(new FileReader(f));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

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

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

        boolean hasMoreTokens() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null) {
                    return false;
                }
                st = new StringTokenizer(s);
            }
            return true;
        }

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

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

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

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

    /**
     * **************************************
     */
    long bin[][] = new long[5005][5005], mod = 998244353L, f[] = new long[5005];

    void solve() {
        long[][] a = new long[5001][5001];
        int i, j, k, mod = 998244353;
        for (i = 0; i <= 5000; i++) {
            a[1][i] = i + 1;
        }
        for (i = 2; i <= 5000; i++) {
            a[i][0] = 1;
            for (j = 1; j <= 5000; j++) {
                a[i][j] = (a[i - 1][j] + j * a[i - 1][j - 1]) % mod;
            }
        }
        i = sc.nextInt();
        j = sc.nextInt();
        k = sc.nextInt();
        long ans = (a[i][j] * a[j][k]) % mod;
        ans = (ans * a[i][k]) % mod;
        out.print(ans);
    }

    private void run() {
//        try {
//            sc = new FastScanner(new File("input.txt"));
////            out = new PrintWriter(new File("output.txt"));
//            out = new PrintWriter(System.out);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }

        sc = new FastScanner(System.in);
        out = new PrintWriter(System.out);
        solve();

        out.close();

    }

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

}


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

/*
TASK: intrigue
LANG: JAVA
 */
public class intrigue {
    static int a , b ,c;
    static long[][] choose;
    static long[][] perm;
    static long mod = 998244353;
    static long sab , sbc , sac;
    public static void main(String[] args) throws IOException {
        FastScanner in = new FastScanner(System.in);
        a = in.nextInt();
        b = in.nextInt();
        c = in.nextInt();
        choose = new long[5001][5001];
        perm = new long[5001][5001];
        perm[0][0] = 1;
        choose[0][0] = 1;
        for(int i = 1;i <= 5000; i++){
            for(int j = 0;j <= i; j++){
                if(j > 0){
                    choose[i][j] = (choose[i-1][j] + choose[i-1][j-1])% mod;
                }
                else {
                    choose[i][j] = 1;
                }
            }
        }
        System.out.println((((func(a , b)*func(b , c))%mod)*func(a , c))%mod);
    }
    public static long func(long a , long b) {
        if(a > b){
            long t = a;
            a = b;
            b = t;
        }
        long sum = 0;
        for(int i = 0;i <= a; i++){
            sum += choose[(int)a][i]*perm(b , i);
            sum %= mod;
        }
        return sum;
    }
    public static long perm(long a , long b){
        if(b == 0)return 1;
        if(b == 1)return a;
        return (a*perm(a-1 , b-1))% mod;
    }
    private static class FastScanner {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

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

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

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

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

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

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

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

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

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


import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        // write your code her
        // Main m = new Main();

        //////// Code Begins //////////////////////////
        Scanner sc = new Scanner(System.in);
        boolean [][] res = new boolean[3][3];
        for(int i=0;i<3;i++){
        	for(int j=0;j<3;j++){
        	int tmp = sc.nextInt();
        		if(tmp%2 == 0)
        			continue;

        		if(i != 0){
        			res[i-1][j] = !res[i-1][j];
        		}
        		if(i != 2){
        			res[i+1][j] = !res[i+1][j];
        		}
        		if(j != 0){
        			res[i][j-1] = !res[i][j-1];
        		}
        		if(j != 2){
        			res[i][j+1] = !res[i][j+1];
        		}
        	}
        }
        for(int i=0;i<3;i++){
        	for(int j=0;j<3;j++){
        		if(!res[i][j])
        			System.out.print("1");
        		else
        			System.out.print("0");
        	}
        	System.out.println();
        }
        //////// Code Ends ///////////////////////////////
    }
}