//package round791;
import java.io.*;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.Queue;

public class F2 {
	InputStream is;
	FastWriter out;
	String INPUT = "";

	void solve()
	{
		int n = ni();
		boolean[][] g = new boolean[10][10];
		for(int m = ni();m > 0;m--){
			int x = ni(), y = ni();
			g[x][y] = g[y][x] = true;
		}
		for(int i = 0;i < 10;i++)g[i][i] = true;

		int[][] njs = new int[1<<9][10];
		for(int j = 0;j < 1<<9;j++) {
			for (int k = 0; k < 10; k++) {
				if (j << ~k >= 0) {
					int nj = j;
					for (int l = 0; l < 10; l++) {
						if (g[k][l]) {
							if (k > l) {
								nj |= 1 << l;
							}
						} else {
							nj &= ~(1 << l);
						}
					}
					njs[j][k] = nj;
				}
			}
		}

		long[] dp = new long[1<<9];
		dp[0] = 1;
		for(int i = 1;i <= n;i++){
			long[] ndp = new long[1<<9];
			for(int j = 0;j < 1<<9;j++){
				for(int k = 0;k < 10;k++){
					if (j << ~k >= 0) {
						int nj = njs[j][k];
						ndp[nj] += dp[j];
						if(ndp[nj] >= mod)ndp[nj] -= mod;
					}
				}
			}
			dp = ndp;
		}
		long ans = sum(dp) % mod;
		out.println(ans);
	}

	public static long sum(long... a){long ret = 0; for(long v : a)ret += v; return ret;}

	public static final int mod = 998244353;
	public static final int G = 3;

	// only 998244353
	public static long[] mul(long[] a, long[] b)
	{
		if(a.length == 0 && b.length == 0)return new long[0];
		if(a.length + b.length >= 300) {
			return Arrays.copyOf(NTTStockham998244353.convolve(a, b), a.length + b.length - 1);
		}else{
			return mulnaive(a, b);
		}
	}

	public static long[] mul(long[] a, long[] b, int lim)
	{
		if(a.length + b.length >= 300) {
			return Arrays.copyOf(NTTStockham998244353.convolve(a, b), lim);
		}else{
			return mulnaive(a, b, lim);
		}
	}

	//	public static final int mod = 1000000007;
	//	public static long[] mul(long[] a, long[] b)
	//	{
	//		if(Math.max(a.length, b.length) >= 3000){
	//			return Arrays.copyOf(NTTCRT.convolve(a, b, 3, mod), a.length+b.length-1);
	//		}else{
	//			return mulnaive(a, b);
	//		}
	//	}

	//	public static long[] mul(long[] a, long[] b, int lim)
	//	{
	//		if(Math.max(a.length, b.length) >= 3000){
	//			return Arrays.copyOf(NTTCRT.convolve(a, b, 3, mod), lim);
	//		}else{
	//			return mulnaive(a, b, lim);
	//		}
	//	}

	public static final long big = (Long.MAX_VALUE/mod/mod-1)*mod*mod;

	public static long[] mulnaive(long[] a, long[] b)
	{
		long[] c = new long[a.length+b.length-1];
		for(int i = 0;i < a.length;i++){
			for(int j = 0;j < b.length;j++){
				c[i+j] += a[i]*b[j];
				if(c[i+j] >= big)c[i+j] -= big;
			}
		}
		for(int i = 0;i < c.length;i++)c[i] %= mod;
		return c;
	}

	public static long[] mulnaive(long[] a, long[] b, int lim)
	{
		long[] c = new long[lim];
		for(int i = 0;i < a.length;i++){
			for(int j = 0;j < b.length && i+j < lim;j++){
				c[i+j] += a[i]*b[j];
				if(c[i+j] >= big)c[i+j] -= big;
			}
		}
		for(int i = 0;i < c.length;i++)c[i] %= mod;
		return c;
	}

	public static class NTTStockham998244353 {
		private static final int P = 998244353, mod = P, G = 3;
		private static long[] wps;

		public static long[] convolve(long[] a, long[] b)
		{
			int m = Math.max(2, Integer.highestOneBit(Math.max(a.length, b.length)-1)<<2);

			wps = new long[m];
			long unit = pow(G, (P-1)/m);
			wps[0] = 1;
			for(int p = 1;p < m;p++) {
				wps[p] = wps[p-1] * unit % mod;
			}

			long[] fa = go(a, m, false);
			long[] fb = a == b ? fa : go(b, m, false);
			for(int i = 0;i < m;i++){
				fa[i] = fa[i]*fb[i] % mod;
			}
			fa = go(fa, m, true);
			for(int i = 1, j = m-1;i < j;i++,j--) {
				long d = fa[i]; fa[i] = fa[j]; fa[j] = d;
			}
			return fa;
		}

		private static void fft(long[] X, long[] Y)
		{
			int s = 1;
			boolean eo = false;
			for(int n = X.length;n >= 4;n /= 2) {
				int m = n/2;
				for(int p = 0;p < m;p++) {
					long wp = wps[s*p];
					long wk = (wp<<32)/P;
					for(int q = 0;q < s;q++) {
						long a = X[q + s*(p+0)];
						long b = X[q + s*(p+m)];
						long ndsts = a + b;
						if(ndsts >= 2*P)ndsts -= 2*P;
						long T = a - b + 2*P;
						long Q = wk*T>>>32;
						Y[q + s*(2*p+0)] = ndsts;
						Y[q + s*(2*p+1)] = wp*T-Q*P&(1L<<32)-1;
					}
				}
				s *= 2;
				eo = !eo;
				long[] D = X; X = Y; Y = D;
			}
			long[] z = eo ? Y : X;
			for(int q = 0;q < s;q++) {
				long a = X[q + 0];
				long b = X[q + s];
				z[q+0] = (a+b) % P;
				z[q+s] = (a-b+2*P) % P;
			}
		}

		//	private static void fft(long[] X, long[] Y)
		//	{
		//		int s = 1;
		//		boolean eo = false;
		//		for(int n = X.length;n >= 4;n /= 2) {
		//			int m = n/2;
		//			for(int p = 0;p < m;p++) {
		//				long wp = wps[s*p];
		//				for(int q = 0;q < s;q++) {
		//					long a = X[q + s*(p+0)];
		//					long b = X[q + s*(p+m)];
		//					Y[q + s*(2*p+0)] = (a+b) % P;
		//					Y[q + s*(2*p+1)] = (a-b+P) * wp % P;
		//				}
		//			}
		//			s *= 2;
		//			eo = !eo;
		//			long[] D = X; X = Y; Y = D;
		//		}
		//		long[] z = eo ? Y : X;
		//		for(int q = 0;q < s;q++) {
		//			long a = X[q + 0];
		//			long b = X[q + s];
		//			z[q+0] = (a+b) % P;
		//			z[q+s] = (a-b+P) % P;
		//		}
		//	}

		private static long[] go(long[] src, int n, boolean inverse)
		{
			long[] dst = Arrays.copyOf(src, n);
			fft(dst, new long[n]);
			if(inverse){
				long in = invl(n);
				for(int i = 0;i < n;i++){
					dst[i] = dst[i] * in % mod;
				}
			}

			return dst;
		}

		private static long pow(long a, long n) {
			//		a %= mod;
			long ret = 1;
			int x = 63 - Long.numberOfLeadingZeros(n);
			for (; x >= 0; x--) {
				ret = ret*ret % mod;
				if (n<<~x<0)ret = ret*a%mod;
			}
			return ret;
		}

		private static long invl(long a) {
			long b = mod;
			long p = 1, q = 0;
			while (b > 0) {
				long c = a / b;
				long d;
				d = a;
				a = b;
				b = d % b;
				d = p;
				p = q;
				q = d - c * q;
			}
			return p < 0 ? p + mod : p;
		}
	}

	public static long C(int n, int r, int mod, int[][] fif) {
		if (n < 0 || r < 0 || r > n) return 0;
		return (long) fif[0][n] * fif[1][r] % mod * fif[1][n - r] % mod;
	}

	public static int[][] enumFIF(int n, int mod) {
		int[] f = new int[n + 1];
		int[] invf = new int[n + 1];
		f[0] = 1;
		for (int i = 1; i <= n; i++) {
			f[i] = (int) ((long) f[i - 1] * i % mod);
		}
		long a = f[n];
		long b = mod;
		long p = 1, q = 0;
		while (b > 0) {
			long c = a / b;
			long d;
			d = a;
			a = b;
			b = d % b;
			d = p;
			p = q;
			q = d - c * q;
		}
		invf[n] = (int) (p < 0 ? p + mod : p);
		for (int i = n - 1; i >= 0; i--) {
			invf[i] = (int) ((long) invf[i + 1] * (i + 1) % mod);
		}
		return new int[][]{f, invf};
	}

	public static class DJSet {
		public int[] upper;

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

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

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

		public boolean unite(int x, int y) {
			x = root(x);
			y = root(y);
			if (x != y) {
				if (upper[y] < upper[x]) {
					int d = x;
					x = y;
					y = d;
				}
				upper[x] += upper[y];
				upper[y] = x;
			}
			return x == y;
		}

		public int count() {
			int ct = 0;
			for (int u : upper) if (u < 0) ct++;
			return ct;
		}

		public int[][] toBucket() {
			int n = upper.length;
			int[][] ret = new int[n][];
			int[] rp = new int[n];
			for (int i = 0; i < n; i++) if (upper[i] < 0) ret[i] = new int[-upper[i]];
			for (int i = 0; i < n; i++) {
				int r = root(i);
				ret[r][rp[r]++] = i;
			}
			return ret;
		}
	}

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

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

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

	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 int[] na(int n)
	{
		int[] a = new int[n];
		for(int i = 0;i < n;i++)a[i] = ni();
		return a;
	}

	private long[] nal(int n)
	{
		long[] a = new long[n];
		for(int i = 0;i < n;i++)a[i] = nl();
		return a;
	}

	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[][] nmi(int n, int m) {
		int[][] map = new int[n][];
		for(int i = 0;i < n;i++)map[i] = na(m);
		return map;
	}

	private int ni() { return (int)nl(); }

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

	public static class FastWriter
	{
		private static final int BUF_SIZE = 1<<13;
		private final byte[] buf = new byte[BUF_SIZE];
		private final OutputStream out;
		private int ptr = 0;

		private FastWriter(){out = null;}

		public FastWriter(OutputStream os)
		{
			this.out = os;
		}

		public FastWriter(String path)
		{
			try {
				this.out = new FileOutputStream(path);
			} catch (FileNotFoundException e) {
				throw new RuntimeException("FastWriter");
			}
		}

		public FastWriter write(byte b)
		{
			buf[ptr++] = b;
			if(ptr == BUF_SIZE)innerflush();
			return this;
		}

		public FastWriter write(char c)
		{
			return write((byte)c);
		}

		public FastWriter write(char[] s)
		{
			for(char c : s){
				buf[ptr++] = (byte)c;
				if(ptr == BUF_SIZE)innerflush();
			}
			return this;
		}

		public FastWriter write(String s)
		{
			s.chars().forEach(c -> {
				buf[ptr++] = (byte)c;
				if(ptr == BUF_SIZE)innerflush();
			});
			return this;
		}

		private static int countDigits(int l) {
			if (l >= 1000000000) return 10;
			if (l >= 100000000) return 9;
			if (l >= 10000000) return 8;
			if (l >= 1000000) return 7;
			if (l >= 100000) return 6;
			if (l >= 10000) return 5;
			if (l >= 1000) return 4;
			if (l >= 100) return 3;
			if (l >= 10) return 2;
			return 1;
		}

		public FastWriter write(int x)
		{
			if(x == Integer.MIN_VALUE){
				return write((long)x);
			}
			if(ptr + 12 >= BUF_SIZE)innerflush();
			if(x < 0){
				write((byte)'-');
				x = -x;
			}
			int d = countDigits(x);
			for(int i = ptr + d - 1;i >= ptr;i--){
				buf[i] = (byte)('0'+x%10);
				x /= 10;
			}
			ptr += d;
			return this;
		}

		private static int countDigits(long l) {
			if (l >= 1000000000000000000L) return 19;
			if (l >= 100000000000000000L) return 18;
			if (l >= 10000000000000000L) return 17;
			if (l >= 1000000000000000L) return 16;
			if (l >= 100000000000000L) return 15;
			if (l >= 10000000000000L) return 14;
			if (l >= 1000000000000L) return 13;
			if (l >= 100000000000L) return 12;
			if (l >= 10000000000L) return 11;
			if (l >= 1000000000L) return 10;
			if (l >= 100000000L) return 9;
			if (l >= 10000000L) return 8;
			if (l >= 1000000L) return 7;
			if (l >= 100000L) return 6;
			if (l >= 10000L) return 5;
			if (l >= 1000L) return 4;
			if (l >= 100L) return 3;
			if (l >= 10L) return 2;
			return 1;
		}

		public FastWriter write(long x)
		{
			if(x == Long.MIN_VALUE){
				return write("" + x);
			}
			if(ptr + 21 >= BUF_SIZE)innerflush();
			if(x < 0){
				write((byte)'-');
				x = -x;
			}
			int d = countDigits(x);
			for(int i = ptr + d - 1;i >= ptr;i--){
				buf[i] = (byte)('0'+x%10);
				x /= 10;
			}
			ptr += d;
			return this;
		}

		public FastWriter write(double x, int precision)
		{
			if(x < 0){
				write('-');
				x = -x;
			}
			x += Math.pow(10, -precision)/2;
			//		if(x < 0){ x = 0; }
			write((long)x).write(".");
			x -= (long)x;
			for(int i = 0;i < precision;i++){
				x *= 10;
				write((char)('0'+(int)x));
				x -= (int)x;
			}
			return this;
		}

		public FastWriter writeln(char c){
			return write(c).writeln();
		}

		public FastWriter writeln(int x){
			return write(x).writeln();
		}

		public FastWriter writeln(long x){
			return write(x).writeln();
		}

		public FastWriter writeln(double x, int precision){
			return write(x, precision).writeln();
		}

		public FastWriter write(int... xs)
		{
			boolean first = true;
			for(int x : xs) {
				if (!first) write(' ');
				first = false;
				write(x);
			}
			return this;
		}

		public FastWriter write(long... xs)
		{
			boolean first = true;
			for(long x : xs) {
				if (!first) write(' ');
				first = false;
				write(x);
			}
			return this;
		}

		public FastWriter writeln()
		{
			return write((byte)'\n');
		}

		public FastWriter writeln(int... xs)
		{
			return write(xs).writeln();
		}

		public FastWriter writeln(long... xs)
		{
			return write(xs).writeln();
		}

		public FastWriter writeln(char[] line)
		{
			return write(line).writeln();
		}

		public FastWriter writeln(char[]... map)
		{
			for(char[] line : map)write(line).writeln();
			return this;
		}

		public FastWriter writeln(String s)
		{
			return write(s).writeln();
		}

		private void innerflush()
		{
			try {
				out.write(buf, 0, ptr);
				ptr = 0;
			} catch (IOException e) {
				throw new RuntimeException("innerflush");
			}
		}

		public void flush()
		{
			innerflush();
			try {
				out.flush();
			} catch (IOException e) {
				throw new RuntimeException("flush");
			}
		}

		public FastWriter print(byte b) { return write(b); }
		public FastWriter print(char c) { return write(c); }
		public FastWriter print(char[] s) { return write(s); }
		public FastWriter print(String s) { return write(s); }
		public FastWriter print(int x) { return write(x); }
		public FastWriter print(long x) { return write(x); }
		public FastWriter print(double x, int precision) { return write(x, precision); }
		public FastWriter println(char c){ return writeln(c); }
		public FastWriter println(int x){ return writeln(x); }
		public FastWriter println(long x){ return writeln(x); }
		public FastWriter println(double x, int precision){ return writeln(x, precision); }
		public FastWriter print(int... xs) { return write(xs); }
		public FastWriter print(long... xs) { return write(xs); }
		public FastWriter println(int... xs) { return writeln(xs); }
		public FastWriter println(long... xs) { return writeln(xs); }
		public FastWriter println(char[] line) { return writeln(line); }
		public FastWriter println(char[]... map) { return writeln(map); }
		public FastWriter println(String s) { return writeln(s); }
		public FastWriter println() { return writeln(); }
	}

	public void trnz(int... o)
	{
		for(int i = 0;i < o.length;i++)if(o[i] != 0)System.out.print(i+":"+o[i]+" ");
		System.out.println();
	}

	// print ids which are 1
	public void trt(long... o)
	{
		Queue<Integer> stands = new ArrayDeque<>();
		for(int i = 0;i < o.length;i++){
			for(long x = o[i];x != 0;x &= x-1)stands.add(i<<6|Long.numberOfTrailingZeros(x));
		}
		System.out.println(stands);
	}

	public void tf(boolean... r)
	{
		for(boolean x : r)System.out.print(x?'#':'.');
		System.out.println();
	}

	public void tf(boolean[]... b)
	{
		for(boolean[] r : b) {
			for(boolean x : r)System.out.print(x?'#':'.');
			System.out.println();
		}
		System.out.println();
	}

	public void tf(long[]... b)
	{
		if(INPUT.length() != 0) {
			for (long[] r : b) {
				for (long x : r) {
					for (int i = 0; i < 64; i++) {
						System.out.print(x << ~i < 0 ? '#' : '.');
					}
				}
				System.out.println();
			}
			System.out.println();
		}
	}

	public void tf(long... b)
	{
		if(INPUT.length() != 0) {
			for (long x : b) {
				for (int i = 0; i < 64; i++) {
					System.out.print(x << ~i < 0 ? '#' : '.');
				}
			}
			System.out.println();
		}
	}

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


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import java.util.Scanner;

/**
 *
 * @author Tue
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        solve();
    }

    public static void solve() {
        Scanner input = new Scanner(System.in);
        String add = input.nextLine();
        String result = "";
        if (add.startsWith("http")) {
            result += "http://";
            if (add.substring(4, add.indexOf("ru")).equals("")) {
                result += add.substring(4, add.lastIndexOf("ru"));
                result += ".ru";
                if (!add.substring(add.lastIndexOf("ru") + 2).equals("")) {
                    result += "/" + add.substring(add.lastIndexOf("ru") + 2);
                }
            } else {
                result += add.substring(4, add.indexOf("ru"));
                result += ".ru";
                if (!add.substring(add.indexOf("ru") + 2).equals("")) {
                    result += "/" + add.substring(add.indexOf("ru") + 2);
                }
            }
        } else {
            result += "ftp://";
            if (add.substring(3, add.indexOf("ru")).equals("")) {
                result += add.substring(3, add.lastIndexOf("ru"));
                result += ".ru";
                if (!add.substring(add.lastIndexOf("ru") + 2).equals("")) {
                    result += "/" + add.substring(add.lastIndexOf("ru") + 2);
                }
            } else {
                result += add.substring(3, add.indexOf("ru"));
                result += ".ru";
                if (!add.substring(add.indexOf("ru") + 2).equals("")) {
                    result += "/" + add.substring(add.indexOf("ru") + 2);
                }
            }
        }
        System.out.println(result);
    }
}


import java.io.*;
import java.math.*;
import java.util.*;
/*public class TaskA {

}
 */
public class TaskA implements Runnable {
	// based on Petr's template
	private void solve() throws IOException {
		int t1 = this.nextInt();
		int t2 = this.nextInt();
		int x1 = this.nextInt();
		int x2 = this.nextInt();
		int t0 = this.nextInt();
		if ( t0 == t2 ){
			if ( t0 == t1 )
				System.out.println( x1 + " " + x2 );
			else
				System.out.println( 0 + " " + x2 );
			return;
		}

		long my1 = 0;
		long my2 = x2;
		for ( int y1 = 0; y1 <= x1; y1 ++ ){
			int div = t2 - t0;
			long y2 = ( 1L * t0 * y1 - 1L * t1 * y1 + div - 1 ) / div;
			if ( y2 > x2 )
				continue;
			long u = 1L * t1 * y1 + 1L * t2 * y2;
			long d = y1 + y2;
			long U = 1L * t1 *my1 + 1L * t2 *my2;
			long D =my1 +my2;
			u -= d * t0;
			U -= D * t0;
			if ( u * D < U * d || ( u * D == U * d && y1 + y2 >= my1 + my2 ) ){
				my1 = y1;
				my2 = y2;
			}
		}
		System.out.println( my1 + " " + my2 );
	}

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

	BufferedReader reader;
	StringTokenizer tokenizer;
	PrintWriter writer;

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

	boolean hasNext() throws IOException {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			String nextLine = reader.readLine();
			if (nextLine == null)
				return false;
			tokenizer = new StringTokenizer(nextLine);
		}

		return true;
	}

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

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

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

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

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

		return tokenizer.nextToken();
	}

	BigInteger nextBigInteger() throws IOException {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			tokenizer = new StringTokenizer(reader.readLine());
		}

		return new BigInteger(tokenizer.nextToken());
	}
}


//comment the next imports before submitting
import java.io.File;
import java.io.PrintStream;
//imports to be deleted ends here

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

//Problem URL here

public class Domino353A {

    public static void solve() {

    }

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

        FastReader reader = new FastReader();

        // int t = reader.nextInt();
        // while (t-- > 0) {
        int n = reader.nextInt();
        boolean uO = false;
        boolean lO = false;
        int uSum = 0;
        int lSum = 0;

        // Integer arr[] = new Integer[n];

        for (int i = 0; i < n; i++) {
            int u = reader.nextInt();
            int l = reader.nextInt();
            if (u % 2 != 0 && l % 2 == 0) {
                uO = true;
            } else if (u % 2 == 0 && l % 2 != 0) {
                lO = true;
            }
            uSum += u;
            lSum += l;
        }

        if (uSum % 2 == 0 && lSum % 2 == 0) {
            System.out.println(0);
        } else if (uSum % 2 != 0 && lSum % 2 == 0) {
            System.out.println(-1);
        } else if (uSum % 2 == 0 && lSum % 2 != 0) {
            System.out.println(-1);
        } else {
            if (lO || uO) {
                System.out.println(1);
            } else {
                System.out.println(-1);
            }
        }

        // Arrays.sort(arr, new Comparator<Integer>() {
        // public int compare(Integer i1, Integer i2) {
        // return i1 - i2;
        // }
        // });

        // System.out.println(Arrays.toString(arr));

        // solve();
        // }

    }

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

}


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

public class Main{

    public static double s(int ax, int ay, int bx, int by, int cx, int cy) {
        double d = Math.abs(ax * (by - cy) + bx * (cy - ay) + cx * (ay - by)) / 2.0;
        return d;
    }

    public static void main(String[] args){
        try{

//            Scanner in = new Scanner(new File("C:\\Users\\VisionLab\\Downloads\\caffe-windows\\caffe-windows\\data\\aesthetics\\test.jpgl"));
//            Scanner ava = new Scanner(new File("C:\\Users\\VisionLab\\Downloads\\caffe-windows\\caffe-windows\\data\\aesthetics\\sorted AVA.txt"));
//            PrintWriter out = new PrintWriter(new File("C:\\Users\\VisionLab\\Downloads\\caffe-windows\\caffe-windows\\data\\aesthetics\\test.txt"));
//
//            int length = 255530;
//
//            int[][] a = new int[length][3];
//            double[] d = new double[length];
//            int[] s = new int[length];
//
//            int threshold = 5;
//            double delta = 0;
//
//            for (int j = 0; j < length; j++) {
//                a[j][0] = ava.nextInt();
//                d[j] = ava.nextDouble();
//                a[j][1] = ava.nextInt();
//                a[j][2] = ava.nextInt();
//                if (d[j] <= threshold - delta) {
//                    s[j] = 0;
//                } else if (d[j] > threshold + delta) {
//                    s[j] = 1;
//                } else {
//                    s[j] = -1;
//                }
//            }
//
//            for (int i = 0; i < 20000; i++) {
//                int id = in.nextInt();
//                for (int j = 0; j < length; j++) {
//                    if (a[j][0] == id) {
//                        if (s[j] != -1) {
//                            System.out.println(i);
//                            out.println("/data/aesthetics/images/" + Integer.toString(a[j][0]) + ".jpg " + s[j]);
//                        }
//                        break;
//                    }
//                }
//            }
//
//            in.close();
//            out.close();
//            ava.close();

            Scanner in = new Scanner(System.in);

            int[] a = new int[5];
            int n = 110;
            int[] b = new int[n];

            int s = 0;

            for (int i = 0; i < 5; i++) {
                a[i] = in.nextInt();
                b[a[i]]++;
                s += a[i];
            }

            Vector<Integer> v = new Vector<Integer>();

            for (int i = 0; i < n; i++) {
                if (b[i] >= 2) {
                    if (b[i] > 3) {
                        b[i] = 3;
                    }
                    v.add(s - b[i] * i);
                }
            }

            if (v.isEmpty()) {
                System.out.println(s);
            } else {
                Collections.sort(v);
                System.out.println(v.elementAt(0));
            }

        } catch(Exception ex) {
            System.out.println(ex.toString());
        }
   }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Duration;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.*;
import java.util.StringJoiner;
import java.util.StringTokenizer;

public class C {

	public static void main(String[] args) throws ParseException {
		FastScanner sc = new FastScanner();
		long n=sc.nextLong(),m=sc.nextLong(),s=sc.nextLong();

		long vert= ((n-1)%s +1 )*((n-1)/s+1)*((m-1)%s +1 )*((m-1)/s+1);
		System.out.println(vert);

	}

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

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

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

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

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

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

}


import java.io.InputStreamReader;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.InputStream;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Stack;
/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Erasyl Abenov
 *
 *
 */
public class Main {
    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
            try (PrintWriter out = new PrintWriter(outputStream)) {
                TaskB solver = new TaskB();
                solver.solve(1, in, out);
            }
    }
}
class TaskB {
    public void solve(int testNumber, InputReader in, PrintWriter out) throws IOException{
        String s = in.next();
        int max = 0;
        for(int i = 0; i < s.length(); ++i){
            for(int j = s.length() - 1; j > i; --j){
                if(max < j - i){
                    String find = s.substring(i, j);
                    int last = s.lastIndexOf(find);
                    int first = s.indexOf(find);
                    if((last >= 0 && last != i) || (first >= 0 && first != i))
                        max = j - i;
                }
            }
        }
        out.println(max);
    }
}
class InputReader {
    private final BufferedReader reader;
    private StringTokenizer tokenizer;
    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream));
        tokenizer = null;
    }
    public String nextLine() {
        try {
            return reader.readLine();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(nextLine());
        }
        return tokenizer.nextToken();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }
    public BigInteger nextBigInteger(){
        return new BigInteger(next());
    }
    public long nextLong() {
        return Long.parseLong(next());
    }
    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


import java.lang.*;
import java.util.*;
public class easyproblem {
    public static void main(String [] args){
        Scanner sc = new Scanner(System.in);
        int length = sc.nextInt();
        int array[] = new int[length];
        int sum = 0;

        for(int i = 0; i < length; i++){
            array[i] = sc.nextInt();
            sum += array[i];
        }

        if(sum > 0){
            System.out.println("HARD");
        }

        else{
            System.out.println("EASY");
        }

        sc.close();
    }
}


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

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

class TaskC {

    public void solve(int testNumber, InputReader in, PrintWriter out) {
        int n = in.nextInt();
        String s = in.next();
        int len = s.length();
        boolean[] evalIfAllFalse = new boolean[len];
        boolean[] evalIfAllTrue = new boolean[len];
        boolean[] triggersOnEvery = new boolean[len];
        boolean[] constantOnEvery = new boolean[len];
        boolean[] canBeFalse = new boolean[len];
        boolean[] canBeTrue = new boolean[len];
        int[] numArgs = new int[len];
        int[] openStack = new int[len];
        int[] opStack = new int[len];
        int sp = 0;
        for (int i = 0; i < len; ++i) {
            char ch = s.charAt(i);
            if (ch == '(') {
                openStack[sp++] = i;
            } else if (ch == '|' || ch == '&' || ch == '^') {
                opStack[sp - 1] = i;
            } else if (ch == ')') {
                --sp;
                int a1 = opStack[sp] - 1;
                int a2 = i - 1;
                char op = s.charAt(opStack[sp]);
                numArgs[i] = numArgs[a1] + numArgs[a2];
                if (op == '|') {
                    evalIfAllFalse[i] = evalIfAllFalse[a1] || evalIfAllFalse[a2];
                    evalIfAllTrue[i] = evalIfAllTrue[a1] || evalIfAllTrue[a2];
                    canBeFalse[i] = canBeFalse[a1] && canBeFalse[a2];
                    canBeTrue[i] = canBeTrue[a1] || canBeTrue[a2];
                    if (!canBeFalse[i]) {
                        triggersOnEvery[i] = false;
                        constantOnEvery[i] = true;
                    } else if (!canBeTrue[a1]) {
                        triggersOnEvery[i] = triggersOnEvery[a2];
                        constantOnEvery[i] = constantOnEvery[a2];
                    } else if (!canBeTrue[a2]) {
                        triggersOnEvery[i] = triggersOnEvery[a1];
                        constantOnEvery[i] = constantOnEvery[a1];
                    } else {
                        triggersOnEvery[i] = false;
                        constantOnEvery[i] = constantOnEvery[a1] && constantOnEvery[a2];
                    }
                } else if (op == '&') {
                    evalIfAllFalse[i] = evalIfAllFalse[a1] && evalIfAllFalse[a2];
                    evalIfAllTrue[i] = evalIfAllTrue[a1] && evalIfAllTrue[a2];
                    canBeFalse[i] = canBeFalse[a1] || canBeFalse[a2];
                    canBeTrue[i] = canBeTrue[a1] && canBeTrue[a2];
                    if (!canBeTrue[i]) {
                        triggersOnEvery[i] = false;
                        constantOnEvery[i] = true;
                    } else if (!canBeFalse[a1]) {
                        triggersOnEvery[i] = triggersOnEvery[a2];
                        constantOnEvery[i] = constantOnEvery[a2];
                    } else if (!canBeFalse[a2]) {
                        triggersOnEvery[i] = triggersOnEvery[a1];
                        constantOnEvery[i] = constantOnEvery[a1];
                    } else {
                        triggersOnEvery[i] = false;
                        constantOnEvery[i] = constantOnEvery[a1] && constantOnEvery[a2];
                    }
                } else if (op == '^') {
                    evalIfAllFalse[i] = evalIfAllFalse[a1] ^ evalIfAllFalse[a2];
                    evalIfAllTrue[i] = evalIfAllTrue[a1] ^ evalIfAllTrue[a2];
                    canBeTrue[i] = (canBeFalse[a1] && canBeTrue[a2]) || (canBeTrue[a1] && canBeFalse[a2]);
                    canBeFalse[i] = (canBeFalse[a1] && canBeFalse[a2]) || (canBeTrue[a1] && canBeTrue[a2]);
                    if ((triggersOnEvery[a1] && constantOnEvery[a2]) || (triggersOnEvery[a2] && constantOnEvery[a1])) {
                        triggersOnEvery[i] = true;
                        constantOnEvery[i] = false;
                    } else if ((triggersOnEvery[a1] && triggersOnEvery[a2]) || (constantOnEvery[a1] && constantOnEvery[a2])) {
                        triggersOnEvery[i] = false;
                        constantOnEvery[i] = true;
                    } else {
                        triggersOnEvery[i] = false;
                        constantOnEvery[i] = false;
                    }
                } else throw new RuntimeException();
            } else if (ch == '0') {
                evalIfAllFalse[i] = false;
                evalIfAllTrue[i] = false;
                triggersOnEvery[i] = false;
                constantOnEvery[i] = true;
                canBeFalse[i] = true;
                canBeTrue[i] = false;
                numArgs[i] = 0;
            } else if (ch == '1') {
                evalIfAllFalse[i] = true;
                evalIfAllTrue[i] = true;
                triggersOnEvery[i] = false;
                constantOnEvery[i] = true;
                canBeFalse[i] = false;
                canBeTrue[i] = true;
                numArgs[i] = 0;
            } else if (ch == '?') {
                evalIfAllFalse[i] = false;
                evalIfAllTrue[i] = true;
                triggersOnEvery[i] = true;
                constantOnEvery[i] = false;
                canBeFalse[i] = true;
                canBeTrue[i] = true;
                numArgs[i] = 1;
            } else throw new RuntimeException();
        }
        if (sp != 0) throw new RuntimeException();
        if (!canBeFalse[len - 1] || !canBeTrue[len - 1]) {
            out.println("NO");
        } else if (evalIfAllFalse[len - 1] != evalIfAllTrue[len - 1]) {
            out.println("YES");
        } else if (constantOnEvery[len - 1]) {
            out.println("NO");
        } else {
            out.println("YES");
        }
	}
}

class InputReader {
    private BufferedReader reader;
    private StringTokenizer tokenizer;

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

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

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

    }


import java.util.*;
public class MyClass {
    public static void main(String args[]) {

        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int arr[]=new int[1000];
        int i;
        for(i=0;i<n;i++)
        arr[i]=sc.nextInt();

        int c=0;
        int max=0;
        int flag=0;
        int t=0;
        int r=0;
        if(arr[0]==1 && arr[1]==2)
        r=1;
        for(i=0;i<n-1;i++)
        {
            if(arr[i+1]==arr[i]+1)
            {
                c++;
                if(i==n-2)
                {
                t=1;
                }
            }
            else
            {
                if(c!=0 && flag==0)
                {
                    if(r==1)
                    max=c+1;
                    else
                    max=c;
                    flag=1;
                }
                else
                {
                    if(c>max)
                     max=c;
                }
                c=0;

            }
        }
        if(t==1 && flag==0)
        {
            if(arr[0]==1 || arr[n-1]==1000)
            {

            System.out.println(c);
            System.exit(0);
            }
        }
        if(t==1)
        {

            if(c>=max && arr[n-1]==1000)
            {
            max=c+1;
            }
            if(c>=max && arr[n-1]!=1000)
            {

            max=c;
            }
        }
        if(max==0)
        System.out.println(0);
        else
        System.out.println(max-1);

        sc.close();

    }
}


import java.util.Scanner;

public class KingShortestPath {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String in1 = scanner.nextLine();
        int x1 = in1.charAt(0) - 'a';
        int y1 = in1.charAt(1) - '1';
        String in2 = scanner.nextLine();
        int x2 = in2.charAt(0) - 'a';
        int y2 = in2.charAt(1) - '1';
        StringBuilder sb = new StringBuilder();
        int count = 0;

        while (true) {
            if(x1 == x2 && y1 == y2) {
                break;
            }

            if(x1 < x2) {
                x1++;
                sb.append("R");
            } else if(x1 > x2) {
                x1--;
                sb.append("L");
            }

            if(y1 < y2) {
                y1++;
                sb.append("U");
            } else if(y1 > y2) {
                y1--;
                sb.append("D");
            }
            count++;

            sb.append("\n");
        }
        System.out.println(count);
        System.out.println(sb.toString());
    }
}


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

public class Main {

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

	void solve(){
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		int f=sc.nextInt();
		int k=sc.nextInt();
		int ans=0;
		int count=0;
		int dir=1;
		int tank=b;

		while(count<k) {
			if(dir==1) {
				if(tank-f<0 || b-(a-f)<0) {
					ans=-1;
					break;
				}
				if(k-count==1) {
					if(tank-a<0) {
						ans++;
						count++;
					}else {
						count++;
					}
				}else {
					if(tank-(2*a-f)<0) {
						ans++;
						tank=b-(a-f);
						count++;
					}else {
						tank-=a;
						count++;
					}
				}
			}
			if(dir==-1) {
				if(tank-(a-f)<0 || b-f<0) {
					ans=-1;
					break;
				}
				if(k-count==1) {
					if(tank-a<0) {
						ans++;
						count++;
					}else {
						count++;
					}
				}else {
					if(tank-(a+f)<0) {
						ans++;
						tank=b-f;
						count++;
					}else {
						tank-=a;
						count++;
					}
				}
			}
			dir*=-1;
		}
		System.out.println(ans);
	}
}


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

public class _400div2Q3
{
    public static void main(String[] args) throws IOException
    {
        FastScanner obj = new FastScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));
		int n = obj.nextInt();

		int index = obj.nextInt();

		int moves = n%6;
		if(moves==0)
			moves+=6;
		if(moves==1)
		{
			if(index==0)
				out.print(1);
			else if(index==1)
				out.print(0);
			else
				out.print(2);
		}
		else if(moves==2)
		{
			if(index==0)
				out.print(1);
			else if(index==1)
				out.print(2);
			else
				out.print(0);
		}
		else if(moves==3)
		{
			if(index==0)
				out.print(2);
			else if(index==1)
				out.print(1);
			else
				out.print(0);
		}
		else if(moves==4)
		{
			if(index==0)
				out.print(2);
			else if(index==1)
				out.print(0);
			else
				out.print(1);
		}
		else if(moves==5)
		{
			if(index==0)
				out.print(0);
			else if(index==1)
				out.print(2);
			else
				out.print(1);
		}
		else if(moves==6)
		{
			if(index==0)
				out.print(0);
			else if(index==1)
				out.print(1);
			else
				out.print(2);
		}

        out.close();
   }

   //-----------PrintWriter for faster output---------------------------------
   public static PrintWriter out;

   //-----------FastScanner class for faster input----------
   public static class FastScanner {
        BufferedReader br;
        StringTokenizer tokenizer;

        public FastScanner() throws IOException {
            br = new BufferedReader(new InputStreamReader(System.in));
            tokenizer = new StringTokenizer(br.readLine().trim());
        }

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

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

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

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

        int[] nextIntArray() throws IOException {
            String[] line = br.readLine().trim().split(" ");
            int[] out = new int[line.length];

            for (int i = 0; i < line.length; i++) {
                out[i] = Integer.valueOf(line[i]);
            }
            return out;
        }

        BigInteger nextBigInteger() throws IOException {
            return new BigInteger(next());
        }

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

   }
   //--------------------------------------------------------
}


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

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

    static class TaskE {
        Debug debug;

        public void solve(int testNumber, FastReader in, PrintWriter out) {
            debug = new Debug(out);
            long n = in.nextLong();
            out.println(rec(n - 1) / 2);
        }

        public static long rec(long n) {
            if (n == 0) return 0;
            if (n % 2 == 0)
                return 2 * rec(n >> 1) + n;
            return 2 * rec(n >> 1) + n + 1;
        }

    }

    static class Debug {
        PrintWriter out;
        boolean oj;
        boolean system;
        long timeBegin;
        Runtime runtime;

        public Debug(PrintWriter out) {
            oj = System.getProperty("ONLINE_JUDGE") != null;
            this.out = out;
            this.timeBegin = System.currentTimeMillis();
            this.runtime = Runtime.getRuntime();
        }

        public Debug() {
            system = true;
            oj = System.getProperty("ONLINE_JUDGE") != null;
            OutputStream outputStream = System.out;
            this.out = new PrintWriter(outputStream);
            this.timeBegin = System.currentTimeMillis();
            this.runtime = Runtime.getRuntime();
        }

    }

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

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

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

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

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

    }
}


/**
 * Created by IntelliJ IDEA.
 * User: Taras_Brzezinsky
 * Date: 8/24/11
 * Time: 8:54 PM
 * To change this template use File | Settings | File Templates.
 */

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

public class TaskD extends Thread {

    public TaskD() {
        this.input = new BufferedReader(new InputStreamReader(System.in));
        this.output = new PrintWriter(System.out);
        this.setPriority(Thread.MAX_PRIORITY);
    }

    private int getIndex(int[][] data, int[] values) {
        for (int i = 0; i < data.length; ++i) {
            if (Arrays.equals(data[i], values)) {
                return i;
            }
        }
        throw new IllegalArgumentException();
    }

    private void generate(int index) {
        if (index == helper.length) {
            states[SIZE++] = helper.clone();
        } else {
            for (int value = 0; value < v[index]; ++value) {
                helper[index] = value;
                generate(index + 1);
            }
        }
    }

    private int[][] pow(int[][] src, long power) {
        int[][] result = new int[src.length][src.length];
        for (int i = 0; i < result.length; ++i) {
            result[i][i] = 1;
        }
        for (; power != 0; power >>= 1) {
            if ((power & 1) == 1) {
                result = multiply(result, src);
            }
            src = multiply(src, src);
        }
        return result;
    }

    private int[][] multiply(int[][] left, int[][] right) {
        int[][] result = new int[left.length][left.length];
        for (int i = 0; i < left.length; ++i) {
            for (int j = 0; j < left.length; ++j) {
                for (int k = 0; k < left.length; ++k) {
                    result[i][j] += (left[i][k] * right[k][j]) % MODULO;
                }
                result[i][j] %= MODULO;
            }
        }
        return result;
    }

    private void solve() throws Throwable {
        long n = nextLong();
        int c = nextInt();
        l = new int[c];
        v = new int[c];
        boolean[] used = new boolean[AlPHABET_SIZE], good = new boolean[AlPHABET_SIZE];

        int total = 1;
        for (int i = 0; i < c; ++i) {
            l[i] = nextToken().charAt(0) - 'A';
            used[l[i]] = true;
            total *= (v[i] = nextInt());
        }
        states = new int[total][];
        helper = new int[c];
        generate(0);
        int[][] grid = new int[total][total];
        for (int current = 0; current < total; ++current) {
            for (int i = 0; i < AlPHABET_SIZE; ++i) {
                helper = states[current].clone();
                if (used[i]) {
                    for (int ind = 0; ind < c; ++ind) {
                        if (l[ind] == i) {
                            helper[ind] = (helper[ind] + 1) % v[ind];
                        }
                    }
                    grid[current][getIndex(states, helper)]++;
                }
            }
        }
        int[][] result = pow(grid, n);
        int answer = 0;
        for (int currentState = 0; currentState < total; ++currentState) {
            Arrays.fill(good, false);
            for (int i = 0; i < c; ++i) {
                good[l[i]] |= states[currentState][i] == 0;
            }
            boolean can = true;
            for (int i = 0; i < AlPHABET_SIZE; ++i) {
                if (used[i] && !good[i]) {
                    can = false;
                    break;
                }
            }
            if (can) {
                answer = (answer + result[0][currentState]) % MODULO;
            }
        }
        output.println(answer);
    }

    public void run() {
        try {
            solve();
        } catch (Throwable e) {
            System.err.println(e.getMessage());
            e.printStackTrace();
            System.exit(666);
        } finally {
            output.flush();
            output.close();
        }
    }

    public static void main(String[] args) {
        new TaskD().start();
    }

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

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

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

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

    private static int[][] states;
    private int[] helper, l, v;
    private static int SIZE = 0;
    private static final int MODULO = 12345, AlPHABET_SIZE = 26;
    private BufferedReader input;
    private PrintWriter output;
    private StringTokenizer tokens = null;
}


import java.util.*;

import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;

public class B {
	FastScanner in;
	PrintWriter out;
	boolean systemIO = true;

	public static void quickSort(int[] a, int from, int to) {
		if (to - from <= 1) {
			return;
		}
		int i = from;
		int j = to - 1;
		int x = a[from + (new Random()).nextInt(to - from)];
		while (i <= j) {
			while (a[i] < x) {
				i++;
			}
			while (a[j] > x) {
				j--;
			}
			if (i <= j) {
				int t = a[i];
				a[i] = a[j];
				a[j] = t;
				i++;
				j--;
			}
		}
		quickSort(a, from, j + 1);
		quickSort(a, j + 1, to);
	}

	public long gcd(long x, long y) {
		if (y == 0) {
			return x;
		}
		if (x == 0) {
			return y;
		}
		return gcd(y, x % y);
	}

	public boolean prime(long x) {
		for (int i = 2; i * i <= x; i++) {
			if (x % i == 0) {
				return false;
			}
		}
		return true;
	}

	public void solve() {
		Random random = new Random();
		long mod = 1000000000 + random.nextInt(1000000);
		while (!prime(mod)) {
			mod = 1000000000 + random.nextInt(1000000);
		}
		BigInteger bigMod = new BigInteger(mod + "");
		long l = System.currentTimeMillis();
		int n = in.nextInt();
		int[] a = new int[101];
		int sum = 0;
		int number = 0;
		for (int i = 0; i < n; i++) {
			int x = in.nextInt();
			a[x]++;
			sum += x;
			if (a[x] == 1) {
				number++;
			}
		}
		if (number == 1) {
			out.println(n);
			return;
		}
		boolean flag = number == 2;
		int s = 0;
		number = 0;
		long[][] dp = new long[n + 1][sum + 1];
		dp[0][0] = 1;
		for (int i = 0; i < a.length; i++) {
			for (int j = 0; j < a[i]; j++) {
				for (int x = number; x >= 0; x--) {
					for (int y = s; y >= 0; y--) {
						dp[x + 1][y + i] += dp[x][y];
						dp[x + 1][y + i] %= mod;
					}
				}
				s += i;
				number++;
			}
		}
		long[] fact = new long[101];
		long[] defact = new long[101];
		fact[0] = 1;
		defact[0] = 1;
		for (int i = 1; i < fact.length; i++) {
			fact[i] = fact[i - 1] * i;
			fact[i] %= mod;
			BigInteger bigInt = new BigInteger(fact[i] + "");
			bigInt = bigInt.modInverse(bigMod);
			defact[i] = bigInt.longValueExact();
		}
		int ans = 0;
		for (int i = 0; i < a.length; i++) {
			for (int j = 1; j <= a[i]; j++) {
				long x = fact[a[i]] * defact[j];
				x %= mod;
				x *= defact[a[i] - j];
				x %= mod;
				if (x == dp[j][j * i]) {
					ans = Math.max(ans, j);
					if (flag && j == a[i]) {
						ans = n;
					}
				}
			}
		}
		out.println(ans);
	}

	public void run() {
		try {
			if (systemIO) {
				in = new FastScanner(System.in);
				out = new PrintWriter(System.out);
			} else {
				in = new FastScanner(new File("input.txt"));
				out = new PrintWriter(new File("output.txt"));
			}
			solve();

			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	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 nextLine() {
			try {
				return br.readLine();
			} catch (IOException e) {
				return null;
			}
		}

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

	}

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


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

public class L {

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

		StringTokenizer st = new StringTokenizer(br.readLine());
		int n = Integer.parseInt(st.nextToken());
		char[] a = br.readLine().toCharArray();
		int[] b = new int[n];
		int max = -1;
		boolean f = true;
		for (int i = 0; i < b.length; i++) {
			if ((a[i] - 'a') >= max) {
				max = a[i] - 'a';
			} else {
				for (int j = i - 1; j >= 0; j--) {
					if (a[j] > a[i] && b[j] == 1)
						f = false;
				}
				if (f)
					b[i] = 1;
				else
					break;
			}
		}
		if(f) {
			pw.println("YES");
			for (int i = 0; i < b.length; i++) {
				pw.print(b[i]);
			}
		}
		else
			pw.println("NO");

		pw.flush();
	}

}


import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.LinkedList;
import java.util.Map.Entry;
import java.util.Queue;
import java.util.Random;
import java.util.Set;
import java.util.SortedSet;
import java.util.Stack;
import java.util.TreeMap;
import java.util.TreeSet;

public class Main
{
	private final int SIZEN = 40;

	public void foo()
	{
		MyScanner scan = new MyScanner();
		int w = scan.nextInt();
		int m = scan.nextInt();
		int[] digit = new int[SIZEN];
		int cnt = 0;
		while(m > 0)
		{
			digit[cnt++] = m % w;
			m /= w;
		}
		for(int i = 0;i < cnt;++i)
		{
			if(digit[i] >= w)
			{
				digit[i] = 0;
				++digit[i + 1];
			}
			if(digit[i] <= 1)
			{
				continue;
			}
			else if(digit[i] == w - 1)
			{
				++digit[i + 1];
			}
			else
			{
				System.out.println("NO");
				return;
			}
		}
		System.out.println("YES");
 	}

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

	class MyScanner
	{
	    private byte[] buf = new byte[1024];
	    private int curChar;
	    private int numChars;
	    BufferedInputStream bis = new BufferedInputStream(System.in);

	    public int read()
	    {
	        if (-1 == numChars)
	        {
	        	throw new InputMismatchException();
	        }
	        if (curChar >= numChars)
	        {
	            curChar = 0;
	            try
	            {
	                numChars = bis.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 long nextLong()
	    {
	    	int c = read();
	    	while (isSpaceChar(c))
	    	{
	    		c = read();
	    	}
	    	int sgn = 1;
	    	if (c == '-')
	    	{
	    		sgn = -1;
	    		c = read();
	    	}
	    	long res = 0;
	    	do
	    	{
	    		if (c < '0' || c > '9')
	    		{
	    			throw new InputMismatchException();
	    		}
	    		res *= 10;
	    		res += c - '0';
	    		c = read();
	    	} while (!isSpaceChar(c));
	    	return res * sgn;
	    }

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

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

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


import java.util.Scanner;

public class test011 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int y = sc.nextInt();
		if (y == 1 && x != 0 || y == 0) {
			System.out.println("NO");
			return;
		}
		int tmp = x - y + 1;
		if (tmp >= 0 && tmp % 2 == 0) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}

	}
}


import java.util.Scanner;

public class _112B_PetyaAndSquare {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        n /= 2;
        if ((a == n || a == n + 1) && (b == n || b == n + 1))
            System.out.println("NO");
        else
            System.out.println("YES");
    }
}


import java.util.*;
import java.io.*;
public class Main {
    static class Scan {
        private byte[] buf=new byte[1024];
        private int index;
        private InputStream in;
        private int total;
        public Scan()
        {
            in=System.in;
        }
        public int scan()throws IOException
        {
            if(total<0)
            throw new InputMismatchException();
            if(index>=total)
            {
                index=0;
                total=in.read(buf);
                if(total<=0)
                return -1;
            }
            return buf[index++];
        }
        public int scanInt()throws IOException
        {
            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();
                }
                else throw new InputMismatchException();
            }
            return neg*integer;
        }
        public double scanDouble()throws IOException
        {
            double doub=0;
            int n=scan();
            while(isWhiteSpace(n))
            n=scan();
            int neg=1;
            if(n=='-')
            {
                neg=-1;
                n=scan();
            }
            while(!isWhiteSpace(n)&&n!='.')
            {
                if(n>='0'&&n<='9')
                {
                    doub*=10;
                    doub+=n-'0';
                    n=scan();
                }
                else throw new InputMismatchException();
            }
            if(n=='.')
            {
                n=scan();
                double temp=1;
                while(!isWhiteSpace(n))
                {
                    if(n>='0'&&n<='9')
                    {
                        temp/=10;
                        doub+=(n-'0')*temp;
                        n=scan();
                    }
                    else throw new InputMismatchException();
                }
            }
            return doub*neg;
        }
        public String scanString()throws IOException
        {
            StringBuilder sb=new StringBuilder();
            int n=scan();
            while(isWhiteSpace(n))
            n=scan();
            while(!isWhiteSpace(n))
            {
                sb.append((char)n);
                n=scan();
            }
            return sb.toString();
        }
        private boolean isWhiteSpace(int n)
        {
            if(n==' '||n=='\n'||n=='\r'||n=='\t'||n==-1)
            return true;
            return false;
        }
    }

    public static void sort(int arr[],int l,int r) {    //sort(arr,0,n-1);
        if(l==r) {
            return;
        }
        int mid=(l+r)/2;
        sort(arr,l,mid);
        sort(arr,mid+1,r);
        merge(arr,l,mid,mid+1,r);
    }
    public static void merge(int arr[],int l1,int r1,int l2,int r2) {
        int tmp[]=new int[r2-l1+1];
        int indx1=l1,indx2=l2;
        //sorting the two halves using a tmp array
        for(int i=0;i<tmp.length;i++) {
            if(indx1>r1) {
                tmp[i]=arr[indx2];
                indx2++;
                continue;
            }
            if(indx2>r2) {
                tmp[i]=arr[indx1];
                indx1++;
                continue;
            }
            if(arr[indx1]<arr[indx2]) {
                tmp[i]=arr[indx1];
                indx1++;
                continue;
            }
            tmp[i]=arr[indx2];
            indx2++;
        }
        //Copying the elements of tmp into the main array
        for(int i=0,j=l1;i<tmp.length;i++,j++) {
            arr[j]=tmp[i];
        }
    }

    public static void sort(long arr[],int l,int r) {    //sort(arr,0,n-1);
        if(l==r) {
            return;
        }
        int mid=(l+r)/2;
        sort(arr,l,mid);
        sort(arr,mid+1,r);
        merge(arr,l,mid,mid+1,r);
    }
    public static void merge(long arr[],int l1,int r1,int l2,int r2) {
        long tmp[]=new long[r2-l1+1];
        int indx1=l1,indx2=l2;
        //sorting the two halves using a tmp array
        for(int i=0;i<tmp.length;i++) {
            if(indx1>r1) {
                tmp[i]=arr[indx2];
                indx2++;
                continue;
            }
            if(indx2>r2) {
                tmp[i]=arr[indx1];
                indx1++;
                continue;
            }
            if(arr[indx1]<arr[indx2]) {
                tmp[i]=arr[indx1];
                indx1++;
                continue;
            }
            tmp[i]=arr[indx2];
            indx2++;
        }
        //Copying the elements of tmp into the main array
        for(int i=0,j=l1;i<tmp.length;i++,j++) {
            arr[j]=tmp[i];
        }
    }

    public static void main(String args[]) throws IOException {
        Scan input=new Scan();
        StringBuilder ans=new StringBuilder("");
        int test=1;
        for(int tt=1;tt<=test;tt++) {
            String str=input.scanString();
            int cnt=0,first=-1;
            for(int i=0;i<str.length();i++) {
                if(first==-1 && str.charAt(i)=='1') {
                    first=i;
                }
                if(str.charAt(i)=='1') {
                    cnt++;
                }
            }
            int fin=0;
            for(int i=0;i<str.length();i++) {
                if(first==-1) {
                    break;
                }
                int indx=str.length()-i-1;
                if(indx%2==0 && i>first) {
                    fin++;
                }
                if(indx%2==0 && i==first && cnt>1) {
                    fin++;
                }
            }
            ans.append(fin+"\n");
        }
        System.out.println(ans);
    }
}


import java.io.InputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.OutputStreamWriter;
import java.io.IOException;
import java.math.BigInteger;
import java.util.*;
import java.util.stream.Stream;

/**
 *
 * @author Pradyumn Agrawal coderbond007
 */
public class Codeforces{
    public static InputStream inputStream = System.in;
    public static FastReader in = new FastReader(inputStream);
    public static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

    public static void main(String[] args)throws java.lang.Exception
    {
        new Codeforces().run();
        out.close();
    }
    void run() throws java.lang.Exception
    {
        int n = ni();
        int[] a = na(n);
        if(Arrays.stream(a).sum() != 0){
            out.println("YES");
            out.println(1);
            out.println(1 + " " + n);
        }else if(Arrays.stream(a).allMatch(x -> x == 0)){
            out.println("NO");
        }else{
            out.println("YES");
            for(int i = 0;i < n;i++){
                if(a[i] != 0){
                    out.println(2);
                    out.println(1 + " " + (i+1));
                    out.println((i+2) + " " + n);
                    return;
                }
            }
        }
    }
    private static int ni(){
        return in.nextInt();
    }
    private static long nl(){
        return in.nextLong();
    }
    private static String ns(){
        return in.nextString();
    }
    private static char nc(){
        return in.nextCharacter();
    }
    private static double nd(){
        return in.nextDouble();
    }

    private static char[] ns(int n)
    {
        char[] a = new char[n];
        for(int i=0;i<n;i++) a[i] = nc();
        return a;
    }

    private static 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 static int[] na(int n)
    {
        int[] a = new int[n];
        for(int i=0;i<n;i++) a[i] = ni();
        return a;
    }

    private static long[] nal(int n)
    {
        long[] a = new long[n];
        for(int i=0;i<n;i++) a[i] = nl();
        return a;
    }
    //private void tr(Object... o) { if(o.length() > 0)System.out.println(Arrays.deepToString(o)); }
}

class FastReader{
    private boolean finished = false;

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

    public FastReader(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 peek(){
        if (numChars == -1){
            return -1;
        }
        if (curChar >= numChars){
            curChar = 0;
            try{
                numChars = stream.read (buf);
            } catch (IOException e){
                return -1;
            }
            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==','){
                c = read();
            }
            if (c < '0' || c > '9'){
                throw new InputMismatchException ();
            }
            res *= 10;
            res += c - '0';
            c = read ();
        } while (!isSpaceChar (c));
        return res * sgn;
    }

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

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

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

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

    private String readLine0(){
        StringBuilder buf = new StringBuilder ();
        int c = read ();
        while (c != '\n' && c != -1){
            if (c != '\r'){
                buf.appendCodePoint (c);
            }
            c = read ();
        }
        return buf.toString ();
    }

    public String nextLine(){
        String s = readLine0 ();
        while (s.trim ().length () == 0)
            s = readLine0 ();
        return s;
    }

    public String nextLine(boolean ignoreEmptyLines){
        if (ignoreEmptyLines){
            return nextLine ();
        }else{
            return readLine0 ();
        }
    }

    public BigInteger nextBigInteger(){
        try{
            return new BigInteger (nextString());
        } catch (NumberFormatException e){
            throw new InputMismatchException ();
        }
    }

    public char nextCharacter(){
        int c = read ();
        while (isSpaceChar (c))
            c = read ();
        return (char) c;
    }

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

    public boolean isExhausted(){
        int value;
        while (isSpaceChar (value = peek ()) && value != -1)
            read ();
        return value == -1;
    }
    public SpaceCharFilter getFilter(){
        return filter;
    }

    public void setFilter(SpaceCharFilter filter){
        this.filter = filter;
    }

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


import static java.lang.System.currentTimeMillis;

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

public class D {

    static void solve() throws IOException {
        // while (true) {
        // testWithVsWithout();
        // if (false) {
        // break;
        // }
        // }
        // test();
        int n = nextInt(), m = nextInt();
//      long time = currentTimeMillis();
        long answer = solve(n, m);
//      System.err.println(currentTimeMillis() - time);
        out.println(answer);
    }

    static void test() {
        for (int n = 1; n < 100; n++) {
            for (int m = 0; 2 * m <= n; m++) {
                long got = solve(n, m);
                long stup = solveStupid(n, m);
                if (got != stup) {
                    throw new AssertionError();
                }
            }
        }
        System.err.println("pass");
    }

    static void testWithVsWithout() {
        Random rng = new Random();
        int n = rng.nextInt(32001);
        while (n < 5) {
            n = rng.nextInt(32001);
        }
        int m = rng.nextInt(n / 2);
        long got = solve(n, m);
        long stup = solveWithoutOptimizations(n, m);
        if (got != stup) {
            throw new AssertionError();
        }
        System.err.println("pass");
    }

    private static long solve(int n, int m) {
        Point[] pointsLeft = new Point[n];
        Point[] pointsRight = new Point[n];
        for (int i = 0; i < n; i++) {
            pointsLeft[i] = new Point((i + 1) * 2, (i + 1) * 2);
            pointsRight[i] = new Point(4 * (n + 1) - (i + 1) * 2, (i + 1) * 2);
            // pointsLeft[i] = new Point((i+1) * 0.5, (i+1) * ok);
            // pointsRight[i] = new Point(n + 1 - (i+1) * 0.5, (i+1) * ok);
        }

        long answer = 0;

        int lastSegmentThing = m;

        int rightStop = n - m;

        for (int leftPointId = m; leftPointId + m < n; leftPointId++) {

            int segmentLeft = -1, segmentRight = -1;

            int xx, yy, theirDx, theirDy;
            long theirAbs, yyyy3;

            {
                int rightPointId = leftPointId;
                xx = pointsLeft[leftPointId].x + pointsRight[rightPointId].x >> 1;
                yy = pointsLeft[leftPointId].y + pointsRight[rightPointId].y >> 1;
                theirDx = xx - pointsLeft[leftPointId].x;
                theirDy = yy - pointsLeft[leftPointId].y;
                theirAbs = (long) theirDx * theirDx + (long) theirDy * theirDy
                        * 3;

                yyyy3 = (long) yy * yy * 3;

                for (int low = lastSegmentThing; low + m < n; low++) {
                    long lowX = 4 * (low + 1);
                    long dx = xx - lowX;
                    long abs = dx * dx + yyyy3;
                    if (abs < theirAbs) {
                        segmentLeft = low;
                        break;
                    }
                }
            }

            // timeFirst += currentTimeMillis();
            int yyyy3i = (int) yyyy3;
            int theirAbsi = (int) theirAbs;
            if (segmentLeft < 0) {
                break;
            }
            lastSegmentThing = segmentLeft;

            segmentRight = n - 1 - segmentLeft;

            answer += segmentRight - segmentLeft + 1;

            int dx;

            int yyyy3MinusTheirAbsi = yyyy3i - theirAbsi;

            int curAddInt = 0;

            for (int rightPointId = leftPointId + 1; rightPointId < rightStop; rightPointId++) {
                --xx;
                ++yy;
                // xx = pointsLeft[leftPointId].x + pointsRight[rightPointId].x
                // >> 1;
                // yy = pointsLeft[leftPointId].y + pointsRight[rightPointId].y
                // >> 1;
                --theirDx;
                ++theirDy;
                // theirDx = xx - pointsLeft[leftPointId].x;
                // theirDy = yy - pointsLeft[leftPointId].y;
                yyyy3MinusTheirAbsi += 2 * theirDx + 1;
                yyyy3MinusTheirAbsi -= 6 * theirDy - 3;
                // theirAbs = theirDx * theirDx + theirDy * theirDy * 3;
                yyyy3MinusTheirAbsi += 6 * yy - 3;
                // if (yyyy3 > Integer.MAX_VALUE) {
                // System.err.println(yyyy3);
                // }
                // long yyyy3 = yy * yy * 3;
                // if (segmentLeft < lastLeftForThisRight[rightPointId]) {
                // segmentLeft = lastLeftForThisRight[rightPointId];
                // }
                // if(segmentRight > lastRightForThisRight[rightPointId]) {
                // segmentRight = lastRightForThisRight[rightPointId];
                // }
                int lowX = 4 * (segmentLeft + 1);
                dx = xx - lowX;
                int abs = dx * dx + yyyy3MinusTheirAbsi;
                while (segmentLeft <= segmentRight) {
                    // if (dx * dx > Integer.MAX_VALUE) {
                    // System.err.println(dx * dx);
                    // }
                    if (abs < 0) {
                        break;
                    } else {
                        ++segmentLeft;
                        abs -= 8 * dx - 16;
                        dx -= 4;
                    }
                }

                lowX = 4 * (segmentRight + 1);
                dx = (xx - lowX);
                abs = dx * dx + yyyy3MinusTheirAbsi;

                while (segmentLeft <= segmentRight) {
                    if (abs < 0) {
                        break;
                    } else {
                        --segmentRight;
                        abs += 8 * dx + 16;
                        dx += 4;
                    }
                }

                if (segmentLeft > segmentRight) {
                    rightStop = rightPointId;
                    break;
                }
                curAddInt += segmentRight - segmentLeft + 1;
            }
            answer += 2L * curAddInt;
        }

        // System.err.println("time first: "+timeFirst);
        // System.err.println("time second: "+timeSecond);
        return answer * 3L;
    }

    private static long solveWithoutOptimizations(int n, int m) {
        Point[] pointsLeft = new Point[n];
        Point[] pointsRight = new Point[n];
        for (int i = 0; i < n; i++) {
            pointsLeft[i] = new Point((i + 1) * 2, (i + 1) * 2);
            pointsRight[i] = new Point(4 * (n + 1) - (i + 1) * 2, (i + 1) * 2);
        }

        long answer = 0;

        int lastSegmentThing = m;

        for (int leftPointId = m; leftPointId + m < n; leftPointId++) {

            int segmentLeft = -1, segmentRight = -1;
            {
                int rightPointId = leftPointId;
                long xx = pointsLeft[leftPointId].x
                        + pointsRight[rightPointId].x >> 1;
                long yy = pointsLeft[leftPointId].y
                        + pointsRight[rightPointId].y >> 1;
                long theirDx = xx - pointsLeft[leftPointId].x;
                long theirDy = yy - pointsLeft[leftPointId].y;
                long theirAbs = theirDx * theirDx + (long) theirDy * theirDy
                        * 3;

                for (int low = lastSegmentThing; low + m < n; low++) {
                    long lowX = 4 * (low + 1);
                    long dx = xx - lowX;
                    long abs = dx * dx + yy * yy * 3;
                    if (abs < theirAbs) {
                        segmentLeft = low;
                        break;
                    }
                }
            }

            if (segmentLeft < 0) {
                break;
            }
            lastSegmentThing = segmentLeft;

            segmentRight = n - 1 - segmentLeft;

            answer += segmentRight - segmentLeft + 1;

            for (int rightPointId = leftPointId + 1; rightPointId < n - m; rightPointId++) {
                long xx = pointsLeft[leftPointId].x
                        + pointsRight[rightPointId].x >> 1;
                long yy = pointsLeft[leftPointId].y
                        + pointsRight[rightPointId].y >> 1;
                long theirDx = xx - pointsLeft[leftPointId].x;
                long theirDy = yy - pointsLeft[leftPointId].y;
                long theirAbs = theirDx * theirDx + theirDy * theirDy * 3;
                while (segmentLeft <= segmentRight) {
                    long lowX = 4 * (segmentLeft + 1);
                    long dx = xx - lowX;
                    long abs = dx * dx + yy * yy * 3;
                    if (abs < theirAbs) {
                        break;
                    } else {
                        ++segmentLeft;
                    }
                }

                while (segmentLeft <= segmentRight) {
                    long lowX = 4 * (segmentRight + 1);
                    long dx = xx - lowX;
                    long abs = dx * dx + yy * yy * 3;
                    if (abs < theirAbs) {
                        break;
                    } else {
                        --segmentRight;
                    }
                }

                if (segmentLeft > segmentRight) {
                    break;
                }
                answer += 2 * (segmentRight - segmentLeft + 1);
            }
        }

        return answer * 3L;
    }

    static long solveStupid(int n, int m) {
        Point[] pointsLeft = new Point[n];
        Point[] pointsRight = new Point[n];
        // double ok = Math.sqrt(3) * 0.5;
        for (int i = 0; i < n; i++) {
            pointsLeft[i] = new Point((i + 1) * 2, (i + 1) * 2);
            pointsRight[i] = new Point(4 * (n + 1) - (i + 1) * 2, (i + 1) * 2);
            // pointsLeft[i] = new Point((i+1) * 0.5, (i+1) * ok);
            // pointsRight[i] = new Point(n + 1 - (i+1) * 0.5, (i+1) * ok);
        }

        long answer = 0;

        for (int leftPointId = m; leftPointId + m < n; leftPointId++) {

            for (int rightPointId = m; rightPointId + m < n; rightPointId++) {
                long xx = pointsLeft[leftPointId].x
                        + pointsRight[rightPointId].x >> 1;
                long yy = pointsLeft[leftPointId].y
                        + pointsRight[rightPointId].y >> 1;

                long theirDx = xx - pointsLeft[leftPointId].x;
                long theirDy = yy - pointsLeft[leftPointId].y;
                long theirAbs = theirDx * theirDx + theirDy * theirDy * 3;

                for (int low = m; low + m < n; low++) {
                    long lowX = 4 * (low + 1);
                    long dx = xx - lowX;
                    long abs = dx * dx + yy * yy * 3;
                    if (abs < theirAbs) {
                        ++answer;
                    }
                }
            }
        }

        return answer * 3L;
    }

    static class Point {
        final int x, y;

        public Point(int x, int y) {
            this.x = x;
            this.y = y;
        }
    }

    static BufferedReader br;
    static StringTokenizer st;
    static PrintWriter out;

    public static void main(String[] args) throws IOException {
        InputStream input = System.in;
        PrintStream output = System.out;
        File file = new File("d.in");
        if (file.exists() && file.canRead()) {
            input = new FileInputStream(file);
        }
        br = new BufferedReader(new InputStreamReader(input));
        out = new PrintWriter(output);
        solve();
        out.close();
    }

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

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

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

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