import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashSet;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.PriorityQueue;
import java.util.TreeSet;
import java.util.function.BiFunction;

public class Main{
	static int n;
	static int mod = 1000000007;
	static long[][] A;
	public static void main(String[] args){
		FastScanner sc = new FastScanner();
		Mathplus mp = new Mathplus();
		PrintWriter out = new PrintWriter(System.out);

		n = sc.nextInt();
		int k = sc.nextInt();
		int num = 0;
		int[] a = new int[n];
		for(int i=0;i<n;i++){
			a[i] = sc.nextInt();
			num+=a[i];
		}
		int d = 0;
		for(int i=0;i<n-num;i++){
			if(a[i]==1) d ++;
		}
		long alle = n*(n-1)/2;
		long mot = mp.rev(alle);
		A = new long[n/2+1][n/2+1];
		for(int i=0;i<=n/2+1;i++){
			if(i!=0){
				A[i][i-1] = i * i * mot%mod;
			}
			if(i!=n/2+1){
				A[i][i+1] =Math.max(0,(n-num-i)) * Math.max(0,num-i) * mot % mod;
			}
			A[i][i] = Math.max(alle - i * i-Math.max(0,n-num-i) * Math.max(0,num-i),0)*mot%mod;
		}
		long[][] ans = pow(A,k);

		System.out.println(ans[d][0]);
	}
	private static long[][] pow(long[][] a2, long k) {
		if(k==1){
			return a2;
		}else{
			if(k%2==0){
				long[][] val = pow(a2,k/2);
				return mul(val,val);
			}else{
				return mul(pow(a2,k-1),A);
			}
		}
	}
	private static long[][] mul(long[][] a, long[][] b) {
		long[][] c = new long[n/2+1][n/2+1];
		for(int i=0;i<n/2+1;i++){
			for(int j=0;j<n/2+1;j++){
				for(int k=0;k<n/2+1;k++){
					c[i][j] += a[i][k] * b[k][j];
					c[i][j] %= mod;
				}
			}
		}
		return c;
	}

}

class SegmentTree<T,E>{
	int N;
	BiFunction<T,T,T> f;
	BiFunction<T,E,T> g;
	T d1;
	ArrayList<T> dat;
	SegmentTree(BiFunction<T,T,T> F,BiFunction<T,E,T> G,T D1,T[] v){
		int n = v.length;
		f = F;
		g = G;
		d1 = D1;
		init(n);
		build(v);
	}

	void init(int n) {
		N = 1;
		while(N<n)N*=2;
		dat = new ArrayList<T>();
	}

	void build(T[] v) {
		for(int i=0;i<2*N;i++) {
			dat.add(d1);
		}
		for(int i=0;i<v.length;i++) {
			dat.set(N+i-1,v[i]);
		}
		for(int i=N-2;i>=0;i--) {
			dat.set(i,f.apply(dat.get(i*2+1),dat.get(i*2+2)));
		}
	}

	void update(int k,E a) {
		k += N-1;
		dat.set(k,g.apply(dat.get(k),a));
		while(k>0){
			k = (k-1)/2;
			dat.set(k,f.apply(dat.get(k*2+1),dat.get(k*2+2)));
		}
	}

	T query(int a,int b, int k, int l ,int r) {
		if(r<=a||b<=l) return d1;
		if(a<=l&&r<=b) return dat.get(k);
		T vl = query(a,b,k*2+1,l,(l+r)/2);
		T vr = query(a,b,k*2+2,(l+r)/2,r);
		return f.apply(vl, vr);
	}
	T query(int a,int b){
		return query(a,b,0,0,N);
	}

}

class LazySegmentTree<T,E> extends SegmentTree<T,E>{
	BiFunction<E,E,E> h;
	BiFunction<E,Integer,E> p = (E a,Integer b) ->{return a;};
	E d0;
	ArrayList<E> laz;
	LazySegmentTree(BiFunction<T,T,T> F,BiFunction<T,E,T> G,BiFunction<E,E,E> H,T D1,E D0,T[] v){
		super(F,G,D1,v);
		int n = v.length;
		h = H;
		d0 = D0;
		Init(n);
	}
	void build() {

	}
	void Init(int n){
		laz = new ArrayList<E>();
		for(int i=0;i<2*N;i++) {
			laz.add(d0);
		}
	}

	void eval(int len,int k) {
		if(laz.get(k).equals(d0)) return;
		if(k*2+1<N*2-1) {
			laz.set(k*2+1,h.apply(laz.get(k*2+1),laz.get(k)));
			laz.set(k*2+2,h.apply(laz.get(k*2+2),laz.get(k)));
		}
		dat.set(k,g.apply(dat.get(k), p.apply(laz.get(k), len)));
		laz.set(k,d0);
	}

	T update(int a,int b,E x,int k,int l,int r) {
		eval(r-l,k);
		if(r<=a||b<=l) {
			return dat.get(k);
		}
		if(a<=l&&r<=b) {
			laz.set(k,h.apply(laz.get(k),x));
			return g.apply(dat.get(k),p.apply(laz.get(k),r-l));
		}
		T vl = update(a,b,x,k*2+1,l,(l+r)/2);
		T vr = update(a,b,x,k*2+2,(l+r)/2,r);
		dat.set(k,f.apply(vl,vr));
		return dat.get(k);

	}

	T update(int a,int b,E x) {
		return update(a,b,x,0,0,N);
	}

	T query(int a,int b,int k,int l,int r) {
		eval(r-l,k);
		if(r<=a||b<=l) return d1;
		if(a<=l&&r<=b) return dat.get(k);
		T vl = query(a,b,k*2+1,l,(l+r)/2);
		T vr = query(a,b,k*2+2,(l+r)/2,r);
		return f.apply(vl, vr);
	}

	T query(int a,int b){
		return query(a,b,0,0,N);
	}

}
class UnionFindTree {
	int[] root;
	int[] rank;
	int[] size;
	UnionFindTree(int N){
		root = new int[N];
		rank = new int[N];
		size = new int[N];
		for(int i=0;i<N;i++){
			root[i] = i;
			size[i] = 1;
		}
	}

	public int find(int x){
		if(root[x]==x){
			return x;
		}else{
			return find(root[x]);
		}
	}

	public void unite(int x,int y){
		x = find(x);
		y = find(y);
		if(x==y){
			return;
		}else{
			if(rank[x]<rank[y]){
				root[x] = y;
				size[y] += size[x];
			}else{
				root[y] = x;
				size[x] += size[y];
				if(rank[x]==rank[y]){
					rank[x]++;
				}
			}
		}
	}

	public boolean same(int x,int y){
		return find(x)==find(y);
	}

}

class ParticalEternalLastingUnionFindTree extends UnionFindTree{
	int[] time;
	int now;
	ParticalEternalLastingUnionFindTree(int N){
		super(N);
		time = new int[N];
		for(int i=0;i<N;i++) {
			time[i] = 1000000007;
		}
	}

	public int find(int t,int i) {
		if(time[i]>t) {
			return i;
		}else {
			return find(t,root[i]);
		}
	}

	public void unite(int x,int y,int t) {
		now = t;
		x = find(t,x);
		y = find(t,y);
		if(x==y)return;
		if(rank[x]<rank[y]){
			root[x] = y;
			size[y] += size[x];
			time[x] = t;
		}else{
			root[y] = x;
			size[x] += size[y];
			if(rank[x]==rank[y]){
				rank[x]++;
			}
			time[y] = t;
		}
	}

	public int sametime(int x,int y) {
		if(find(now,x)!=find(now,y)) return -1;
		int ok = now;
		int ng = 0;
		while(ok-ng>1) {
			int mid = (ok+ng)/2;
			if(find(mid,x)==find(mid,y)) {
				ok = mid;
			}else {
				ng = mid;
			}
		}
		return ok;
	}

}
class Graph {
	ArrayList<Edge>[] list;
	int size;

	TreeSet<LinkEdge> Edges = new TreeSet<LinkEdge>(new LinkEdgeComparator());

	@SuppressWarnings("unchecked")
	Graph(int N){
		size = N;
		list = new ArrayList[N];
		for(int i=0;i<N;i++){
			list[i] = new ArrayList<Edge>();
		}
	}

	void addEdge(int a,int b){
		list[a].add(new Edge(b,1));
	}

	void addWeightedEdge(int a,int b,long c){
		list[a].add(new Edge(b,c));
	}

	void addEgdes(int[] a,int[] b){
		int size = a.length;
		for(int i=0;i<size;i++){
			list[a[i]].add(new Edge(b[i],1));
		}
	}

	void addWeighterEdges(int[] a ,int[] b ,int[] c){
		int size = a.length;
		for(int i=0;i<size;i++){
			list[a[i]].add(new Edge(b[i],c[1]));
		}
	}

	long[] bfs(int s){
		long[] L = new long[size];
		for(int i=0;i<size;i++){
			L[i] = -1;
		}
		L[s] = 0;
		ArrayDeque<Integer> Q = new ArrayDeque<Integer>();
		Q.add(s);

		while(!Q.isEmpty()){
			int v = Q.poll();
			for(Edge e:list[v]){
				int w = e.to;
				long c = e.cost;
				if(L[w]==-1){
					L[w] = L[v] + c;
					Q.add(w);
				}
			}
		}

		return L;
	}

	long[] dijkstra(int s){
		long[] L = new long[size];
		for(int i=0;i<size;i++){
			L[i] = -1;
		}
		int[] visited = new int[size];
		L[s] = 0;
		PriorityQueue<Pair> Q = new PriorityQueue<Pair>(new SampleComparator());
		Q.add(new Pair(0,s));

		while(!Q.isEmpty()){

			Pair C = Q.poll();
			if(visited[(int)C.b]==0){
				L[(int)C.b] = C.a;
				visited[(int) C.b] = 1;
				for(Edge D:list[(int) C.b]){
					Q.add(new Pair(L[(int)C.b]+D.cost,D.to));
				}
			}
		}

		return L;
	}
	long[] maxtra(int s,long l){
		long[] L = new long[size];
		for(int i=0;i<size;i++){
			L[i] = -1;
		}
		int[] visited = new int[size];
		L[s] = -1;
	;
		PriorityQueue<Pair> Q = new PriorityQueue<Pair>(new SampleComparator());
		Q.add(new Pair(l,s));

		while(!Q.isEmpty()){

			Pair C = Q.poll();
			if(visited[(int)C.b]==0){
				L[(int)C.b] = C.a;
				visited[(int) C.b] = 1;
				for(Edge D:list[(int) C.b]){
					Q.add(new Pair(Math.max(L[(int)C.b],D.cost),D.to));
				}
			}
		}

		return L;
	}
	long Kruskal(){
		long ans = 0;
		for(int i=0;i<size;i++) {
			for(Edge e:list[i]) {
				Edges.add(new LinkEdge(e.cost,i,e.to));
			}
		}
		UnionFindTree UF = new UnionFindTree(size);
		for(LinkEdge e:Edges){
			if(e.a>=0&&e.b>=0) {
				if(!UF.same(e.a,e.b)){
					ans += e.L;
					UF.unite(e.a,e.b);
				}
			}
		}

		return ans;
	}

	ArrayList<Integer> Kahntsort(){

		ArrayList<Integer> ans = new ArrayList<Integer>();
		PriorityQueue<Integer> q = new PriorityQueue<Integer>();
		int[] in = new int[size];
		for(int i=0;i<size;i++) {
			for(Edge e:list[i]) {
				in[e.to]++;
			}
		}
		for(int i=0;i<size;i++) {
			if(in[i]==0) {
				q.add(i);
			}
		}
		while(!q.isEmpty()) {
			int v = q.poll();
			ans.add(v);
			for(Edge e:list[v]) {
				in[e.to]--;
				if(in[e.to]==0) {
					q.add(e.to);
				}
			}
		}
		for(int i=0;i<size;i++) {
			if(in[i]>0)return new ArrayList<Integer>();
		}
		return ans;
	}

	RootedTree dfsTree(int i) {
		int[] used = new int[size];
		RootedTree r = new RootedTree(size);
		dfsTree(i,used,r);
		return r;

	}

	private void dfsTree(int i, int[] used, RootedTree r) {
		used[i] = 1;
		for(Edge e:list[i]) {
			if(used[e.to]==0) {
				r.list[i].add(e);
				used[e.to] = 1;
				dfsTree(i,used,r);
			}
		}

	}
}

class Tree extends Graph{

	public Tree(int N) {
		super(N);
	}

	long[] tyokkei(){
		long[] a = bfs(0);

		System.out.println();
		int maxdex = -1;
		long max = 0;
		for(int i=0;i<size;i++){
			if(max<a[i]){
				max = a[i];
				maxdex = i;
			}
		}

		long[] b = bfs(maxdex);
		System.out.println();
		int maxdex2 = -1;
		long max2 = 0;
		for(int i=0;i<size;i++){
			if(max2<b[i]){
				max2 = b[i];
				maxdex2 = i;
			}
		}
		long[] ans = {max2,maxdex,maxdex2};
		return ans;
	}

}

class RootedTree extends Graph{

	RootedTree(int N){
		super(N);
	}

}
class LinkEdge{
	long L;
	int a ;
	int b;
	LinkEdge(long l,int A,int B){
		L = l;
		a = A;
		b = B;
	}
	public boolean equals(Object o){
		LinkEdge O = (LinkEdge) o;
		if(O.a==this.a&&O.b==this.b&&O.L==this.L){
			return true;
		}else{
			return false;
		}

	}

	public int hashCode(){
		return Objects.hash(L,a,b);
	}

}

class Edge{
	int to;
	long cost;

	Edge(int a,long b){
		to = a;
		cost = b;
	}

}
class LinkEdgeComparator implements Comparator<LinkEdge>{
	public int compare(LinkEdge P, LinkEdge Q) {
		long temp = P.L-Q.L;
		if(temp==0){
			if(P.a>Q.a){
				return 1;
			}else{
				if(P.b>Q.b){
					return 1;
				}else{
					return -1;
				}
			}

		}
		if(temp>=0){
			return 1;
		}else{
			return -1;
		}
	}

}
class Pair{
	long a;
	long b;

	Pair(long p,long q){
		this.a = p;
		this.b = q;
	}

	public boolean equals(Object o){
		Pair O = (Pair) o;
		if(O.a==this.a&&O.b==this.b){
			return true;
		}else{
			return false;
		}

	}

	public int hashCode(){
		return Objects.hash(a,b);
	}

}

class SampleComparator implements Comparator<Pair>{
	public int compare(Pair P, Pair Q) {
		long temp = P.a-Q.a;
		if(temp==0){
			if(P.b>Q.b){
				return 1;
			}else{
				return -1;
			}

		}
		if(temp>=0){
			return 1;
		}else{
			return -1;
		}
	}

}

class LongIntPair{
	long a;
	int b;

	LongIntPair(long p,int q){
		this.a = p;
		this.b = q;
	}

	public boolean equals(Object o){
		Pair O = (Pair) o;
		if(O.a==this.a&&O.b==this.b){
			return true;
		}else{
			return false;
		}

	}

	public int hashCode(){
		return Objects.hash(a,b);
	}

}

class LongIntSampleComparator implements Comparator<LongIntPair>{
	public int compare(LongIntPair P, LongIntPair Q) {
		long temp = P.a-Q.a;
		if(temp==0){
			if(P.b>Q.b){
				return 1;
			}else{
				return -1;
			}

		}
		if(temp>=0){
			return 1;
		}else{
			return -1;
		}
	}

}

class FastScanner {
    private final java.io.InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
    public boolean hasNext() { skipUnprintable(); return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return (minus ? -n : n);
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return (int) (minus ? -n : n);
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
}

class Mathplus{
	int mod = 1000000007;
	long[] fac = new long[1000001];
	long[][] combt = new long[2001][2001];
	long[][] permt = new long[2001][2001];
	boolean isBuild = false;
	boolean isBuildc = false;
	boolean isBuildp = false;
	int mindex = -1;
	int maxdex = -1;

	void buildFac(){
		fac[0] = 1;
		for(int i=1;i<=1000000;i++){
			fac[i] = (fac[i-1] * i)%mod;
		}
		isBuild = true;
	}

	void buildComb() {
		for(int i=0;i<=2000;i++) {
			combt[i][0] = 1;
		}
		for(int j=1;j<=2000;j++) {
			combt[j][j] = 1;
			for(int i=j+1;i<=2000;i++) {
				combt[i][j] = combt[i-1][j-1] + combt[i-1][j];
				if(combt[i][j]>=mod)combt[i][j]-=mod;
			}

		}
		isBuildc = false;
	}

	void buildPerm() {
		for(int i=0;i<=2000;i++) {
			permt[i][0] = 1;
		}
		if(!isBuild)buildFac();
		for(int i=1;i<=2000;i++) {
			for(int j=1;j<=i;j++) {
				permt[i][j] = permt[i][j-1]*(i-j+1);
				permt[i][j] %= mod;
			}
		}
		isBuildp = true;
	}

	public int isBigger(int[] d, int i) {
		int ok = d.length;
		int ng = -1;
		while(Math.abs(ok-ng)>1) {
			int mid = (ok+ng)/2;
			if(d[mid]>i) {
				ok = mid;
			}else {
				ng = mid;
			}
		}
		return ok;
	}

	public int isSmaller(int[] d, int i) {
		int ok = -1;
		int ng = d.length;
		while(Math.abs(ok-ng)>1) {
			int mid = (ok+ng)/2;
			if(d[mid]<i) {
				ok = mid;
			}else {
				ng = mid;
			}
		}
		return ok;
	}

	public HashSet<Integer> primetable(int m) {
		HashSet<Integer> pt = new HashSet<Integer>();
		for(int i=2;i<=m;i++) {
			boolean b = true;
			for(int d:pt) {
				if(i%d==0) {
					b = false;
					break;
				}
			}
			if(b) {
				pt.add(i);
			}
		}
		return pt;
	}

	long max(long[] a){
		long max = 0;
		for(int i=0;i<a.length;i++){
			if(max<a[i]){
				max =a[i];
				maxdex = i;
			}
		}
		return max;
	}
	int max(int[] a){
		int max = 0;
		for(int i=0;i<a.length;i++){
			if(max<a[i]){
				max =a[i];
				maxdex = i;
			}
		}
		return max;
	}
	long min(long[] a){
		long min = Long.MAX_VALUE;
		for(int i=0;i<a.length;i++){
			if(min>a[i]){
				min =a[i];
				mindex = i;
			}
		}
		return min;
	}
	int min(int[] a){
		int min = Integer.MAX_VALUE;
		for(int i=0;i<a.length;i++){
			if(min>a[i]){
				min =a[i];
				mindex = i;
			}
		}
		return min;
	}
	long sum(long[] a){
		long sum = 0;
		for(int i=0;i<a.length;i++){
			sum += a[i];
		}
		return sum;
	}
	long sum(int[] a){
		long sum = 0;
		for(int i=0;i<a.length;i++){
			sum += a[i];
		}
		return sum;
	}

	long gcd(long a, long b){
		if(a<b){
			a^=b;
			b^=a;
			a^=b;
		}
		if(a%b==0){
			return b;
		}else{
			return gcd(b,a%b);
		}
	}

	long lcm(long a, long b){
		return a / gcd(a,b) * b;
	}

	public long perm(int a,int num) {
		if(a<2000&&num<2000) {
			if(!isBuildp) {
				buildPerm();
				isBuildp = true;
 			}
			return permt[a][num];
		}
		if(!isBuild) {
			buildFac();
		}
		return fac[a] * (rev(fac[a-num]))%mod;
	}
	public long comb(int a,int num){
		if(a<2000&&num<2000) {
			if(!isBuildc) {
				buildComb();
				isBuildc = true;
 			}
			return combt[a][num];
		}
		if(!isBuild){
			buildFac();
		}
		return fac[a] * (rev(fac[num])*rev(fac[a-num])%mod)%mod;
	}

	long rev(long l) {
		return pow(l,mod-2);
	}

	long pow(long l, int i) {
		if(i==0){
			return 1;
		}else{
			if(i%2==0){
				long val = pow(l,i/2);
				return val * val % mod;
			}else{
				return pow(l,i-1) * l % mod;
			}
		}
	}

}


import java.io.PrintWriter;
import java.util.Scanner;

public class C {

    /**
     * @param args
     */
    public static void main(String[] args) {
        Subs subs = new Subs();
        subs.sol();
        subs.print();
    }

}

class Subs {

    Subs() {
        Scanner scr = new Scanner(System.in);
        String fs = scr.nextLine();
        String ft = scr.nextLine();
        s = fs.toCharArray();
        t = ft.toCharArray();
        scr.close();
    }

    void sol() {
        long[][] dp = new long[s.length + 1][t.length + 1];

        ans = 0;
        for (int i = 1; i <= s.length; i++){
            for (int j = 1; j <= t.length; j++){

                /* de facto, but it's too slowly
                if (s[i-1] == t[j-1]) {
                    for (int k = 0; k < j; k++){
                        dp[i][j] = (dp[i][j] + dp[i-1][k]) % M;
                    }
                    dp[i][j] += 1;
                    ans = (ans + dp[i][j]) % M;
                */

                dp[i][j] = dp[i][j-1];
                if (s[i-1] == t[j-1]){
                    dp[i][j] = (dp[i][j] + dp[i-1][j-1] + 1) % M;
                }
            }
        }
        for (int i = 1; i <= s.length; i++){
            ans = (ans + dp[i][t.length]) % M;
        }
    }

    void print() {
        PrintWriter pw = new PrintWriter(System.out);
        pw.println(ans);
        pw.flush();
        pw.close();
    }

    long ans;
    char[] s;
    char[] t;
    static final int M = 1000000007;
}


import java.util.*;

import D.Pair;

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

public class C {
	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 long pow(long x, long p) {
		if (p == 0) {
			return 1;
		}
		long t = pow(x, p / 2);
		t *= t;
		t %= mod;
		if (p % 2 == 1) {
			t *= x;
			t %= mod;
		}
		return t;
	}

	public class Pair implements Comparable<Pair> {
		long x;
		long y;

		public Pair(long x, long y) {
			this.x = x;
			this.y = y;
		}

		@Override
		public int compareTo(Pair o) {
			if (x > o.x) {
				return 1;
			}
			if (x < o.x) {
				return -1;
			}
			if (y > o.y) {
				return 1;
			}
			if (y < o.y) {
				return -1;
			}
			return 0;
		}
	}

	long mod = 1000000007;

	ArrayList<Integer>[] to;
	HashSet<Integer> used = new HashSet<>();

	public void solve() {
		long[] arr = {in.nextLong(), in.nextLong()};
		Arrays.sort(arr);
		long a = arr[0];
		long b = arr[1];
		if (a == b) {
			out.println(0);
			return;
		}
		long d = b - a;
		TreeSet<Pair> ans = new TreeSet<>();
		for (long i = 1; i * i <= d; i++) {
			if (d % i == 0) {
				long k = (i - a % i) % i;
				ans.add(new Pair((a + k) * (b + k) / gcd(a + k, b + k), k));
//				System.out.println(i + " " + (a + k) * (b + k) / gcd(a + k, b + k) + " " + k);
				i = d / i;
				k = (i - a % i) % i;
				ans.add(new Pair((a + k) * (b + k) / gcd(a + k, b + k), k));
//				System.out.println(i + " " + (a + k) * (b + k) / gcd(a + k, b + k) + " " + k);
				i = d / i;
			}
		}
		out.println(ans.first().y);
//		long t = System.currentTimeMillis();
//		long min = a * b;
//		long ans = 0;
//		long k = 0;
//		while (System.currentTimeMillis() - t < 700) {
//			long minth = (a + k) * (b + k) / gcd(a + k, b + k);
//			if (minth < min) {
//				min = minth;
//				ans = k;
//			}
//			k++;
//		}
//		System.err.println(k);
//		out.println(ans);
	}

	private void dfs(int i) {
		used.add(i);
		for (int j : to[i]) {
			if (!used.contains(j)) {
				dfs(j);
			}
		}
	}

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


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

public class Pangram {
	public static void main(String args[]) throws Exception {
		Scanner in;
		try {
			in = new Scanner(new File("input.txt"));
		}
		catch (Exception e) {
			in = new Scanner(System.in);
		}
		int n = in.nextInt();
		String arch = in.next();
		arch = arch.toUpperCase();
		int[] alpha = new int[26];
		if (n < 26) {
			System.out.println("NO");
		}
		else {
			for (int i = 0; i < 26 ; i++) {
				for (int j = 0; j < arch.length(); i++) {
					if ((i + 65) == arch.charAt(j)) alpha[i] ++;
				}
			}
			int min = alpha[0];
		    for (int i = 1; i < 26; i++) {
			    min = Math.min(min, alpha[i]);
		    }
		    if (min > 0) System.out.println("YES");
		    else System.out.println("NO");
	    }

	}
}


import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.util.*;

public class Codeforces {

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

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

		FastReader in = new FastReader();
		OutputStream out = new BufferedOutputStream ( System.out );

		long x = in.nextLong();
		long y = in.nextLong();
		int n = in.nextInt();

		long[] a = new long[n + 1];

		a[1] = x;
		a[2] = y;

		for(int i = 3; i <= n; i++) {
			a[i] = (a[i-1] - a[i-2]);
			if(a[i] < 0) a[i] += 1000000007;
			a[i] = a[i] %1000000007;
		}

		if(a[n] < 0) a[n] = (a[n] + 1000000007) %1000000007;

		out.write((a[n] + "\n").getBytes());
		out.flush();

	}

}


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

public class Main {

	public static void main(String[] args)
	{
		BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
		try {
			String entrada = read.readLine();
			String respuesta = "";
			char[] letras = entrada.toCharArray();
			char[] letrasRes = new char[letras.length];
			int i = (letras.length-1)/2;
			if(letras.length == 2)
			{
				i++;
			}
			int j = 0;
			while(j < letras.length)
			{
				letrasRes[j] = letras[i];
				j++;
				if(i > (letras.length-1)/2)
				{
					i -= j;
				}
				else
				{
					i += j;
				}
			}
			respuesta = String.valueOf(letrasRes);
			System.out.println(respuesta);
			read.close();
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}


import java.util.*;

public class Solution{
    public static void main(String []args){

        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int num=n;
        boolean flag=false;
        while(num!=0&&flag==false){
            if(num%10==4||num%10==7){
                num=num/10;
            }
            else{
                if(num%4==0||num%7==0)
                flag=true;
            }
        }
        if(num==0){
        System.out.println("YES");
        //break;
        }
        else if(flag==true)
        System.out.println("YES");
        else
        System.out.println("NO");
    }
}


import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (true) {
            int day=in.nextInt();
            String s=in.nextLine();
            if (s.contains("month")) {
                if (day>=30) {
                    System.out.println("11");
                }
                else
                    System.out.println("12");
            }
            else
                if (day==7) {
                    System.out.println(48);
            }
                else {
                    System.out.println(52);
            }
        }
    }

}


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

import Utils.MathUtils;

public final class Main
{
	static long mod = 998244353l;

	public static void main(String[] args) throws IOException
	{
		Scanner in = getScan(args);
		// int tt = in.nextInt();
		// while (tt-- > 0)
		// {
		int n = in.nextInt();
		int m = in.nextInt();
		long res = MathUtils.divMod(fact(m), fact(n - 1) * fact(m - n + 1), mod);

		if (n < 3)
		{
			System.out.println(0);
			return;
		}
		long pow = MathUtils.binpowMod(2, n - 3, mod);
		long tmp = (pow * (n - 2)) % mod;
		res = (res * tmp) % mod;
		System.out.println(res);
		// }
	}

	public static long fact(int n)
	{
		long res = 1;
		for (int i = 1; i <= n; i++)
		{
			res = (res * i) % mod;
		}
		return res;
	}

	public static int log2nlz(int bits)
	{
		if (bits == 0) return 0; // or throw exception
		return 31 - Integer.numberOfLeadingZeros(bits);
	}

	static Scanner getScan(String[] args) throws IOException
	{
		if (args.length == 0)
		{
			return new Scanner(System.in);
		}
		else
		{
			return new Scanner(new File(args[0]));
		}
	}

	static BufferedReader getBuffer(String[] args) throws IOException
	{
		if (args.length == 0)
		{
			return new BufferedReader(new InputStreamReader(System.in));
		}
		else
		{
			return new BufferedReader(new FileReader(args[0]));
		}
	}

}


import java.util.Scanner;

public class project {
    public static long answ(long n) {
        long t2 = 1, t3 = 1, x = 0, y = 0;
        long cnt = 0;

        while (t2 <= n) {
            x++;
            t2 *= 2;
        }

        cnt += x;
        x--;
        t2 /= 2;

        while (t3 <= n) {
            y++;
            t3 *= 3;

            while (t2 * t3 > n) {
                x--;
                t2 /= 2;
            }

            cnt += x + 1;
        }
    }

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

    	long L = s.nextInt(), R = s.nextInt();

    	System.out.println(answ(R) - answ(L - 1));
    }
}


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

import java.util.Scanner;

/**
 *
 * @author DELL
 */
public class Wizards_and_Demonstration {
    public static void solve(){
        Scanner nera = new Scanner(System.in);
        int n=nera.nextInt();
        int x=nera.nextInt();
        int y=nera.nextInt();

        System.out.println((int)Math.ceil((y*n/100.0))-x);
    }
    public static void main(String[] args) {

        solve();

    }
}


import java.util.*;

public class flowers
{
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		int r = (int)in.nextLong();
		int g = (int)in.nextLong();
		int b = (int)in.nextLong();
		// int count = 0;
		// int min = Math.min(r, g);
		// min = Math.min(min, b);
		// int reduce = (min/3)*3;
		// count += reduce;
		// r-=reduce;
		// g-=reduce;
		// b-=reduce;

		int max = Math.max(r, g);
		max = Math.max(max, b);
		int[] dp = new int[max+1];
		dp[0] = 0; //count;
		for(int i=1; i<=max; i++)
		{
			if(i<3){
				if(r>=i && g>=i && b>=i)
					dp[i] = 1+dp[i-1];
			}
			else{
				dp[i] = dp[i-1];
				int temp = dp[i-3];
				if(r>=i) temp++;
				if(g>=i) temp++;
				if(b>=i) temp++;
				dp[i] = Math.max(temp, dp[i]);
				if(r>=i && g>=i && b>=i)
					dp[i]= Math.max(1+dp[i-1], dp[i]);
			}
		}
		System.out.println(dp[max]);
	}
}


import java.util.*;

public class points {
	static int minRemove = Integer.MAX_VALUE;
	static int[] x;
	static int n, d;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		d = sc.nextInt();
		x = new int[n];

		for (int i=0; i<n; i++) {
			x[i] = sc.nextInt();
		}
		Arrays.sort(x);
		minimize(0, n-1);
		System.out.println(minRemove);
	}
	public static void minimize(int i, int j) {
		if (n-(j-i+1)>minRemove) return;
		if (x[j]-x[i] <= d) {minRemove = Math.min(minRemove, n -(j-i+1)); return;}
		minimize(i+1, j);
		minimize(i, j-1);
	}
}


package problemsolving;

import java.util.*;

public class ProblemSolving {

    public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);

        int n = scan.nextInt();
        int arr[] = new int[n];
        for(int i =0;i<n;i++){
            arr[i] = scan.nextInt();
        }
        String x = "";
        Arrays.sort(arr);
        for(int i =0;i<arr.length;i++){
            x+=arr[i]+" ";
        }
        System.out.println(x.trim());

    }

}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
import static java.lang.Math.*;

public class B {
    static char[][] maprot;
    static int[][] dp;
    static int[][] available;
    static int[] log;
    static int n;

    public static int f(int i, int mask) {
        if (dp[i][mask] != Integer.MIN_VALUE)
            return dp[i][mask];
        char c = maprot[i][log[mask & -mask]];
        int current = c == 'a' ? 1 : c == 'b' ? -1 : 0;
        if (i == n + n - 2)
            return dp[i][mask] = current;
        else {
            int ret = (i & 1) == 0 ? 31 : -31;
            for (int j = 0; j < 26; j++) {
                int next = i < n - 1 ? (mask | mask << 1) : (mask | mask >> 1);
                int intersection = available[i + 1][j] & next;
                if (intersection != 0) {
                    if ((i & 1) == 0)
                        ret = min(ret, current + f(i + 1, intersection));
                    else
                        ret = max(ret, current + f(i + 1, intersection));
                }
            }
            return dp[i][mask] = ret;
        }
    }

    public static void main(String[] args) throws Exception {
        log = new int[1 << 20];
        for (int i = 0; i < 20; i++)
            log[1 << i] = i;
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer strtok;
        strtok = new StringTokenizer(in.readLine());
        n = Integer.parseInt(strtok.nextToken());
        char[][] map = new char[n][];
        for (int i = 0; i < n; i++)
            map[i] = in.readLine().toCharArray();
        maprot = new char[n + n - 1][];
        for (int i = 0; i < n + n - 1; i++) {
            int count = 0;
            // kasal b2a w kda -_-
            for (int j = 0; j <= i; j++) {
                if (j >= n || i - j >= n)
                    continue;
                count++;
            }
            int top = 0;
            maprot[i] = new char[count];
            for (int j = 0; j <= i; j++) {
                if (j >= n || i - j >= n)
                    continue;
                maprot[i][top++] = map[i - j][j];
            }
        }
        dp = new int[n + n - 1][];
        for (int i = n + n - 2; i >= 0; i--) {
            dp[i] = new int[1 << maprot.length];
            Arrays.fill(dp[i], Integer.MIN_VALUE);
        }
        available = new int[n + n - 1][26];
        for (int i = 0; i < maprot.length; i++) {
            for (int k = 0; k < maprot[i].length; k++) {
                available[i][maprot[i][k] - 'a'] |= 1 << k;
            }
        }
        int k = f(0, 1);
        if (k == 0)
            System.out.println("DRAW");
        else if (k > 0)
            System.out.println("FIRST");
        else
            System.out.println("SECOND");
    }
}


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

public class StringPlay {
    public static final int UNREACHABLE = 1000;

    FastScanner in;
    PrintWriter out;

    public void solve() throws IOException {
        int n = in.nextInt();
        char[][] t = new char[n][n];
        for (int i = 0; i < n; i++) {
            t[i] = in.next().toCharArray();
        }

        int[] curr = new int[1 << n];
        Arrays.fill(curr, UNREACHABLE);
        curr[1 << (n - 1)] = getValue(t[n - 1][n - 1]);

        int[] next = new int[1 << n];

        for (int layer = 2 * n - 2; layer > 0; layer--) {
            boolean first = layer % 2 == 0;
            Arrays.fill(next, UNREACHABLE);

            for (int state = 0; state < curr.length; state++) {
                if (curr[state] == UNREACHABLE) {
                    continue;
                }

                int[] nextMask = new int['z' - 'a' + 1];
                for (int row = 0; row < n; row++) {
                    int col = layer - row;
                    if (col < 0 || col > n - 1) {
                        continue;
                    }
                    int bit = 1 << col;
                    if ((state & bit) == 0) {
                        continue;
                    }

                    if (col > 0) {
                        int ch = t[row][col - 1] - 'a';
                        nextMask[ch] += (1 << (col - 1));
                    }
                    if (row > 0) {
                        int ch = t[row - 1][col] - 'a';
                        nextMask[ch] += (1 << col);
                    }
                }

                for (int i = 0; i < nextMask.length; i++) {
                    int add = getValue((char) ('a' + i));
                    int mask = nextMask[i];
                    if (mask == 0) {
                        continue;
                    }

                    if (next[mask] == UNREACHABLE) {
                        next[mask] = curr[state] + add;
                    }
                    if (first) {
                        next[mask] = Math.max(next[mask], curr[state] + add);
                    } else {
                        next[mask] = Math.min(next[mask], curr[state] + add);
                    }
                }
            }

            int[] tmp = next;
            next = curr;
            curr = tmp;
        }

        if (curr[1] == 0) {
            out.println("DRAW");
        } else {
            out.println(curr[1] > 0 ? "FIRST" : "SECOND");
        }
    }

    private int getValue(char c) {
        return c != 'a' ? c == 'b' ? -1 : 0 : 1;
    }

    public void run() {
        try {
            in = new FastScanner(System.in);
            out = new PrintWriter(System.out);

            solve();

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

    class FastScanner {
        BufferedReader br;
        StringTokenizer st;

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

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

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


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

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

	void solve()
	{
		int n = ni(), k = ni();
		char[] s = ns(n);
		for(int i = 0;i < n-1 && k > 0;i++){
			if(s[i] == '4' && s[i+1] == '7'){
				if(i % 2 == 0){
					s[i+1] = '4';
					k--;
				}else{
					s[i] = '7';
					k--;
					if(i-1 >= 0 && s[i-1] == '4'){
						k %= 2;
						i = -1;
					}
				}
			}
		}
		out.println(new String(s));
	}

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

	public int ni()
	{
		try {
			int num = 0;
			boolean minus = false;
			while((num = is.read()) != -1 && !((num >= '0' && num <= '9') || num == '-'));
			if(num == '-'){
				num = 0;
				minus = true;
			}else{
				num -= '0';
			}

			while(true){
				int b = is.read();
				if(b >= '0' && b <= '9'){
					num = num * 10 + (b - '0');
				}else{
					return minus ? -num : num;
				}
			}
		} catch (IOException e) {
		}
		return -1;
	}

	public long nl()
	{
		try {
			long num = 0;
			boolean minus = false;
			while((num = is.read()) != -1 && !((num >= '0' && num <= '9') || num == '-'));
			if(num == '-'){
				num = 0;
				minus = true;
			}else{
				num -= '0';
			}

			while(true){
				int b = is.read();
				if(b >= '0' && b <= '9'){
					num = num * 10 + (b - '0');
				}else{
					return minus ? -num : num;
				}
			}
		} catch (IOException e) {
		}
		return -1;
	}

	public String ns()
	{
		try{
			int b = 0;
			StringBuilder sb = new StringBuilder();
			while((b = is.read()) != -1 && (b == '\r' || b == '\n' || b == ' '));
			if(b == -1)return "";
			sb.append((char)b);
			while(true){
				b = is.read();
				if(b == -1)return sb.toString();
				if(b == '\r' || b == '\n' || b == ' ')return sb.toString();
				sb.append((char)b);
			}
		} catch (IOException e) {
		}
		return "";
	}

	public char[] ns(int n)
	{
		char[] buf = new char[n];
		try{
			int b = 0, p = 0;
			while((b = is.read()) != -1 && (b == ' ' || b == '\r' || b == '\n'));
			if(b == -1)return null;
			buf[p++] = (char)b;
			while(p < n){
				b = is.read();
				if(b == -1 || b == ' ' || b == '\r' || b == '\n')break;
				buf[p++] = (char)b;
			}
			return Arrays.copyOf(buf, p);
		} catch (IOException e) {
		}
		return null;
	}

	double nd() { return Double.parseDouble(ns()); }
	boolean oj = System.getProperty("ONLINE_JUDGE") != null;
	void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}


import java.util.Scanner;
import java.util.ArrayList;
public class MaximApartmentMain{

  public static void main(String[] args){
    (new MaximApartment()).run();
  }
}
class Combination {
    private boolean permutationEnabled;
    private boolean debug = false;
    private ArrayList<ObjectArray> result = new ArrayList();

    public Combination(boolean permutationEnabled){
        this.permutationEnabled = permutationEnabled;
    }
    public void debugPrintln(String s){
        if(debug) System.out.println(s);
    }
    public void debugPrint(String s){
        if(debug) System.out.print(s);
    }
    //Main method that runs on start
    public void run(int[] array, int subsetAmount){
        if(array.length > 0 && subsetAmount <= array.length && subsetAmount > 0){
            printCombination(array, array.length, subsetAmount);
        }
        else{
            debugPrintln("ERROR: Incorrect parametres provided");
        }
    }

    //The main function that prints all combinations of size r
    // in arr[] of size n. This function mainly uses combinationUtil()
    public void printCombination(int arr[], int n, int r){
        // A temporary array to store all combination one by one
        int data[]=new int[r];

        // Print all combination using temprary array 'data[]'
        combinationUtil(arr, data, 0, n-1, 0, r);
    }

    /* arr[]  ---> Input Array
    data[] ---> Temporary array to store current combination
    start & end ---> Staring and Ending indexes in arr[]
    index  ---> Current index in data[]
    r ---> Size of a combination to be printed */
    public void combinationUtil(int arr[], int data[], int start, int end, int index, int r){
        // Current combination is ready to be added as a subset as all the indices have been filled
        if (index == r)
        {
            ObjectArray subset = new ObjectArray(data[0]);
            for (int j=1; j<r; j++)
                subset.add(data[j]);

            if(!permutationEnabled) result.add(subset);
            else{
                ArrayList<Integer> values = subset.getArrayList();
                int[] array = new int[values.size()];
                int counter = 0;
                for(int value: values){
                    array[counter] = value;
                    counter++;
                }
                heapPermutation(array, array.length, array.length);
            }

            return;
        }

        // replace index with all possible elements. The condition
        // "end-i+1 >= r-index" makes sure that including one element
        // at index will make a combination with remaining elements
        // at remaining positions
        for (int i=start; i<=end && end-i+1 >= r-index; i++)
        {
            data[index] = arr[i];
            combinationUtil(arr, data, i+1, end, index+1, r);
        }
    }

    public ArrayList<ObjectArray> getSubset(){
        return result;
    }

    //Generating permutation using Heap Algorithm
    public void heapPermutation(int array[], int size, int n)
    {
        // if size becomes 1 then prints the obtained
        // permutation
        if (size == 1){
            ObjectArray subset = new ObjectArray(array[0]);
            for(int i=1; i < array.length; i++){
                subset.add(array[i]);
            }
            result.add(subset);
        }

        for (int i=0; i<size; i++)
        {
            heapPermutation(array, size-1, n);

            // if size is odd, swap first and last
            // element
            if (size % 2 == 1)
            {
                int temp = array[0];
                array[0] = array[size-1];
                array[size-1] = temp;
            }

            // If size is even, swap ith and last
            // element
            else
            {
                int temp = array[i];
                array[i] = array[size-1];
                array[size-1] = temp;
            }
        }
    }
}
class ObjectArray {
    private ArrayList<Integer> integerArray;
    private ArrayList<String> stringArray;
    private ArrayList<Double> doubleArray;
    private boolean debug = false;
    private int selected;

    public ObjectArray(ArrayList<Integer> array){
        integerArray = array;
        selected = 1;
    }
    public ObjectArray(int value){
        integerArray = new ArrayList<>();
        integerArray.add(value);
        selected = 1;
    }
    public ObjectArray(String value){
        stringArray = new ArrayList<>();
        stringArray.add(value);
        selected = 2;
    }
    public ObjectArray(double value){
        doubleArray = new ArrayList<>();
        doubleArray.add(value);
        selected = 3;
    }
    public void debugPrintln(String s){
        if(debug) System.out.println(s);
    }
    public void debugPrint(String s){
        if(debug) System.out.print(s);
    }
    public void add(int value){
        if(selected == 1){
            integerArray.add(value);
        }
        else{
            debugPrintln("ERROR: Array not created");
        }
    }
    public void add(String value){
        if(selected == 2){
            stringArray.add(value);
        }
        else{
            debugPrintln("ERROR: Array not created");
        }
    }
    public void add(double value){
        if(selected == 3){
            doubleArray.add(value);
        }
        else{
            debugPrintln("ERROR: Array not created");
        }
    }
    public ArrayList getArrayList(){
        switch(selected){
            case 1:
                return integerArray;
            case 2:
                return stringArray;
            case 3:
                return doubleArray;
            default:
                return null;
        }
    }
}
class MaximApartment {
    private int[] result; //Holds the number of good apartments for each combination
    private final boolean debug = false; //Debug Mode

    public void debugPrintln(String s){
        if(debug) System.out.println(s);
    }
    public void debugPrint(String s){
        if(debug) System.out.print(s);
    }
    //Takes and returns the input argument
    public int[] getInput(){
        int[] result = {-1, -1};
        boolean stop = false;
        Scanner s = new Scanner(System.in);
        int val1 = -1;
        int val2 = -1;
        debugPrintln("Please provide the number of apartments followed by a space followed by the number of good apartments");
        String input = s.nextLine();
        String[] inputVal = input.split(" ");
        if(inputVal.length == 2){
            val1 = Integer.parseInt(inputVal[0]);
            val2 = Integer.parseInt(inputVal[1]);
            if(((val1 > 0 && val1 <= Math.pow(10, 9))) && (val2 >= 0 && val2 <= val1)){
                result[0] = val1;
                result[1] = val2;
                stop = true;
            }
        }

        return result;
    }

    public int[] getMinMax(){
        int[] val = new int[2];
        if(result != null){
            int min = Integer.MAX_VALUE;
            int max = Integer.MIN_VALUE;
            for(int i=0; i < result.length; i++){
                if(result[i] < min) min = result[i];
                if(result[i] > max) max = result[i];
            }
            val[0] = min;
            val[1] = max;
        }

        return val;
    }
    //Main function that takes input and displays the output
    public void run(){
        int[] inputs = getInput();
        if(inputs[0] != -1 && inputs[1] != -1){
            Combination c = new Combination(false); //True for permutation
            int[] apartments = new int[inputs[0]]; //List of apartments

            //Create aparments
            debugPrintln("Creating list of apartments");
            for(int i=0; i < apartments.length; i++){
                apartments[i] = i+1;
            }

            c.run(apartments, inputs[1]); //Generate set of combinations of the apartment

            ArrayList<ObjectArray> set = c.getSubset();
            debugPrintln("Created possible sets of good apartments. Total number of possible combinations: " + set.size());

            result = new int[set.size()];
            int currentResultIndex = 0;
            for(ObjectArray s: set){
                ArrayList<Integer> combination = s.getArrayList();
                for(int i=2; i < apartments.length; i++){
                    if(!combination.contains(i) && ((combination.contains(i-1)) || (combination.contains(i+1)))){
                        result[currentResultIndex]++;
                    }
                }
                if(combination.contains(2) && !combination.contains(1)) result[currentResultIndex]++;
                if(combination.contains(apartments.length-1) && !combination.contains(apartments.length)) result[currentResultIndex]++;

                currentResultIndex++;
            }

            int[] outputs = getMinMax();
            if(outputs[0] != Integer.MAX_VALUE && outputs[1] != Integer.MIN_VALUE){
                System.out.println(outputs[0] + " " + outputs[1]);
            }
            else{
                System.out.println(0 + " " + 0);
            }
        }

    }
}


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

public class E implements Runnable {
	public static void main (String[] args) {new Thread(null, new E(), "_cf", 1 << 28).start();}

	int n;
	int MAX = 51;
	HashMap<Integer, Integer>[] dp;

	public void run() {
		FastScanner fs = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		System.err.println("Go!");

		int a = fs.nextInt(), b = fs.nextInt();
		n = fs.nextInt();

		dp = new HashMap[MAX];
		for(int i = 0; i < MAX; i++) dp[i] = new HashMap<Integer, Integer>();

		int ret = solve(b, a);
		if(ret == 1) System.out.println("Masha");
		else if(ret == 0) System.out.println("Missing");
		else System.out.println("Stas");

		out.close();
	}

	//returns -1 if whoever is playing here loses
	//returns 1 otherwise
	int solve(int a, int b) {
		if(a >= MAX) { //draw
			return 0;
		}
		if(b >= 10000) {
			int moves = (n-1)-b;
			if(moves % 2 == 1) {
				return 1;
			}

			return -1;
		}
		if(dp[a].containsKey(b)) return dp[a].get(b);
//		System.out.printf("Items %d Boxes: %d\n", a, b);

		boolean canDraw = false;
		if(!isBad(a, b + 1)) { //increase number of boxes
			int ret = solve(a, b + 1);
			if(ret == -1) { //i win
				dp[a].put(b, 1);
				return 1;
			}
			canDraw |= ret == 0;
		}

		if(!isBad(a + 1, b)) { //increase number of items
			int ret = solve(a + 1, b);
			if(ret == -1) {
				dp[a].put(b, 1);
				return 1;
			}
			canDraw |= ret == 0;
		}

		int ret = -1;
		if(canDraw) ret = 0;

		dp[a].put(b, ret);
		return ret;
	}

	boolean isBad(int a, int b) {
		double one = a * Math.log(b);
		double two = Math.log(n);
		return one > two || Math.abs(one-two) < 1e-9;
	}

	class FastScanner {
		public int BS = 1<<16;
		public char NC = (char)0;
		byte[] buf = new byte[BS];
		int bId = 0, size = 0;
		char c = NC;
		double num = 1;
		BufferedInputStream in;

		public FastScanner() {
			in = new BufferedInputStream(System.in, BS);
		}

		public FastScanner(String s) throws FileNotFoundException {
			in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
		}

		public char nextChar(){
			while(bId==size) {
				try {
					size = in.read(buf);
				}catch(Exception e) {
					return NC;
				}
				if(size==-1)return NC;
				bId=0;
			}
			return (char)buf[bId++];
		}

		public int nextInt() {
			return (int)nextLong();
		}

		public long nextLong() {
			num=1;
			boolean neg = false;
			if(c==NC)c=nextChar();
			for(;(c<'0' || c>'9'); c = nextChar()) {
				if(c=='-')neg=true;
			}
			long res = 0;
			for(; c>='0' && c <='9'; c=nextChar()) {
				res = (res<<3)+(res<<1)+c-'0';
				num*=10;
			}
			return neg?-res:res;
		}

		public double nextDouble() {
			double cur = nextLong();
			return c!='.' ? cur:cur+nextLong()/num;
		}

		public String next() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c>32) {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public String nextLine() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c!='\n') {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public boolean hasNext() {
			if(c>32)return true;
			while(true) {
				c=nextChar();
				if(c==NC)return false;
				else if(c>32)return true;
			}
		}

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

	}

}


import java.math.BigInteger;
import java.util.Scanner;
public class practica8
{
    public static void main(String[] args){
       Scanner ingreso=new Scanner(System.in);
       String numero=ingreso.next();
       BigInteger b=new BigInteger("5");
       BigInteger a=new BigInteger("5");
       BigInteger c=new BigInteger("0");
       BigInteger d=new BigInteger("1");

        for (int i = 1; i >0; i++) {
            a=a.multiply(b);
            c=c.add(d);
            String conv=""+c;
            if(conv.equals(numero))
            {
                i=-1;

            }
        }

       int tam=(""+a).length();
       String cadena="";
        for (int i = tam-1; i >(tam-3) ; i--) {
          cadena=cadena+(""+a).charAt(i);
        }
        String cadfinal="";
        for (int i = 1; i >=0; i--) {
         cadfinal=cadfinal+(cadena.charAt(i));
       }
        System.out.println(cadfinal);
    }
}


import java.util.Scanner;
import java.util.Stack;

public class Code_For_1 {

	public static void populate(Stack<Integer> series, long num)
	{
		if(num<2)
		{
			series.push((int) num);
			return;
		}

		populate(series,num/2);
		series.push((int) (num%2));
		populate(series,num/2);
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in=new Scanner(System.in);
		long num=in.nextLong();
		long l=in.nextLong();
		long r=in.nextLong();

		Stack<Integer> series=new Stack<>();

		populate(series,num);

		int count=0;

		for(int i=(int) (l-1);i<r;i++)
		{
			if(series.get(i)==1)
			{
				count++;
			}
		}

		System.out.println(count);
	}

}


import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class   CodeFor1 {

    public static ArrayList<Character> BinaryArry(long n,long end)
    {
        ArrayList<Integer> binary_arr = new ArrayList<>();
        while(true)
        {
            binary_arr.add((int)n%2);
            n = n/2;
            if(n==1||n==0)
                break;
        }
        Collections.reverse(binary_arr);
        int num = element_num(end, binary_arr.size());
        return finalarr((int) n, binary_arr, num );
    }

    public static int element_num(long n ,int size)
    {
        long num=3;
        int j=2;
        for(int i=0;i<size;i++)
        {
           if(n<=num)
               return i;
           num=(long) (num+(Math.pow(2, j)));
           j++;

        }
        return 1;
    }

    public static ArrayList<Character> finalarr(int n , ArrayList<Integer> arr , int number)
    {
        ArrayList<Character> reternedarr = new ArrayList<>();
        reternedarr.add(Integer.toString(n).charAt(0));
        for(int i=0;i<=number;i++)
        {
            ArrayList<Character> copyarr = new ArrayList<>(reternedarr);
            reternedarr.add(Integer.toString(arr.get(i)).charAt(0));
            if(i!=number)
               reternedarr.addAll(copyarr);
        }
        return reternedarr;
    }

    public static int sizeOF (ArrayList<Character> arr , int start , int size )
    {
        int count = 0;
        for(int i = 1 ; i<=size+1 ; i++)
        {
            if(start>arr.size())
                start=1;
            if(arr.get(start-1).equals('1'))
                count++;
            start++;
        }
        return count;
    }

    public static void main(String[] args) {
     Scanner scan = new Scanner(System.in);
     long n,l,r,out = 0;
     n = scan.nextLong();
     l = scan.nextLong();
     r = scan.nextLong();
     ArrayList<Character>  arr = new ArrayList<>();
     int length;
     if(l>r)
     {
         length = (int) (l-r);
         arr = BinaryArry(n, l);
         if(r>arr.size())
             r=r-arr.size();
         out = sizeOF(arr, (int) r,length);
     }
     else
     {
         length = (int) (r-l);
         arr = BinaryArry(n, r);
         if(l>arr.size())
             l=l-arr.size();
         out = sizeOF(arr, (int) l,length);
     }

     System.out.println(out);
    }
}


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

public class Main {

    static HashSet<int[]> ts;
    static int sols;

    public static void makeSols(int n) {
        sols = -1;
        for (int x = 0; x <= n; x++) {
            for (int y = 0; y <= n; y++) {
                for (int z = 0; z <= n; z++) {
                    for (int w = 0; w <= n; w++) {
                        if (x + y + z + w == n) {
                            int sol[] = new int[4];
                            sol[0] = x;
                            sol[1] = y;
                            sol[2] = z;
                            sol[3] = w;
                            ts.add(sol);
                        }
                    }
                }
            }
        }
    }

    public static void main(String args[]) throws Exception {
        BufferedReader br = new BufferedReader(new FileReader(new File("in.txt")));
        //BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

        while (br.ready()) {
            String l[] = br.readLine().split("[ ]+");
            ts = new HashSet<int[]>();
            makeSols(Integer.parseInt(l[0]));
       //     System.out.println("--->");
            int k=Integer.parseInt(l[1]);
            int  min=Integer.MAX_VALUE;
            for (int[] x : ts) {
                if (2 * x[0] + 3 * x[1] + 4*x[2] + 5*x[3]==k) {
                    min=Math.min(min, x[0]);
                }
            }
            System.out.println(min);

        }

    }
}


2import java.util.Scanner;

public class Main {
    public static void main(String args[]){
        Scanner cin = new Scanner(System.in);
        while (cin.hasNext()){
            int i = cin.nextInt();
            if (tbl[i] == -1) while(true);
            System.out.println(tbl[i]);
        }
    }
    public static int []tbl = {-2, 2, -1, 1, -1, -1};
}


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

	public static void main(String[] args) {
		InputReader in = new InputReader();
		int n = in.nextInt();
		int m = in.nextInt();

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

		Arrays.sort(arr);
		arr = reverseOrder(arr);

		int[] sums = new int[n];
		sums[0] = arr[0];
		for (int i=1; i<n; i++)
			sums[i] = sums[i-1] + arr[i];

		if (m > sums[n-1])
			System.out.println(-1);
		else
			System.out.println(binarySearch(arr, sums, m));
	}

	public static int binarySearch(int[] arr, int[] sums, int m) {
		int l = 1; int r = arr.length;
		while (l != r) {
			if (l+1 == r)
				return isPossible(l, arr, sums, m) ? l : r;
			int mid = (l + r)/2;
			if (isPossible(mid, arr, sums, m))
				r = mid;
			else
				l = mid+1;
		}
		return l;
	}

	public static boolean isPossible(int day, int[] arr, int[] sums, int val) {
		int tot = sums[day-1], numUsed = day, sub = 1, prevUsed = 0;
		while (numUsed < arr.length) {
			prevUsed = numUsed;
			numUsed = Math.min(numUsed + day, arr.length);
			int pos = binarySearch(sub, arr);
			if (pos >= numUsed)
				tot += sums[numUsed-1] - sums[prevUsed-1] - (numUsed-prevUsed)*sub;
			else if (pos > prevUsed) {
				int index = prevUsed + (day - (numUsed - pos) - 1);
				tot += (sums[index] - sums[prevUsed-1]) - (day - (numUsed - pos))*sub;
			}
			++sub;
		}
		return tot >= val;
	}

	public static int binarySearch(int T, int[] arr) {
		int l = 0, r = arr.length;
		while (l != r) {
			int mid = (l + r)/2;
			if (arr[mid] <= T)
				r = mid;
			else
				l = mid+1;
		}
		return l;
	}

	public static int[] reverseOrder(int[] arr) {
		int[] newArr = new int[arr.length];
		for (int i=0; i<arr.length; i++)
			newArr[i] = arr[arr.length-1-i];
		return newArr;
	}

	static class InputReader {
		public BufferedReader br;
		public StringTokenizer st;

		public InputReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
			st = null;
		}

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

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


import java.util.*;
public class free{
public static void main(String  args[]){
Scanner sc=new Scanner(System.in);
int n =sc.nextInt();
int fingers=0;
int dima=0;
int fr[]=new int[n];
for(int i=0;i<n;i++){
fr[i]=sc.nextInt();
fingers+=fr[i];
}
dima=2;

if((fingers+dima)%(n+1)!=0){
dima=1;
}

System.out.println(dima);

}

}


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

public class J implements Runnable {

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

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

    private void init() throws FileNotFoundException {
        Locale.setDefault(Locale.US);
        String fileName = "";
        if (ONLINE_JUDGE && fileName.isEmpty()) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        } else {
            if (fileName.isEmpty()) {
                in = new BufferedReader(new FileReader("input.txt"));
                out = new PrintWriter("output.txt");
            } else {
                in = new BufferedReader(new FileReader(fileName + ".in"));
                out = new PrintWriter(fileName + ".out");
            }
        }
    }

    String readString() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());

        }
        return tok.nextToken();
    }

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

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

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

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

    public static void main(String[] args) {
        //new Thread(null, new _Solution(), "", 128 * (1L << 20)).start();
        new J().run();
    }

    long timeBegin, timeEnd;

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

    @Override
    public void run() {
        try {
            timeBegin = System.currentTimeMillis();
            init();
            solve();
            out.close();
            time();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(-1);
        }
    }

    int[][][][] dp;
    char[] s;
    int INF = 10000000;

    int solve(int v, int k, int x, int last) {
        if (v < 0) return INF;
        if (k < 0) return INF;
        if (x < 0) return INF;
        if (dp[v][k][x][last] != -1) {
            return dp[v][k][x][last];
        }
        int res = INF;
        if (last == 0 && v > 0) {
            //v
            for (int i = 0; i < 3; i++) {
                res = Math.min(res, solve(v - 1, k, x, i));
            }
            return res + count(s, 'V', v, k, x);
        }
        if (last == 1 && k > 0) {
            //K
            res = Math.min(solve(v, k - 1, x, 1), solve(v, k - 1, x, 2));
            return res + count(s, 'K', v, k, x);
        }
        if (last == 2 && x > 0) {
            for (int i = 0; i < 3; i++) {
                res = Math.min(res, solve(v, k, x - 1, i));
            }
            return res + + count(s, 'X', v, k, x);
        }
        return INF;
    }

    int count(char[] s, char target, int v, int k, int x) {
        int answer = 0;
        for (char c : s) {
            if (c == 'V') {
                v--;
                if (v == 0 && target == 'V') return answer;
                if (v < 0) answer++;
            }
            if (c == 'K') {
                k--;
                if (k == 0 && target == 'K') return answer;
                if (k < 0) answer++;
            }
            if (c == 'X') {
                x--;
                if (x == 0 && target == 'X') return answer;
                if (x < 0) answer++;
            }
        }
        throw new RuntimeException();
    }

    private void solve() throws IOException {
        int n = readInt();
        s = readString().toCharArray();
        int vcnt = 0, kcnt = 0, xcnt = 0;
        for (int i = 0; i < s.length; i++) {
            if (s[i] == 'V') {
                vcnt++;
                continue;
            }
            if (s[i] == 'K') {
                kcnt++;
                continue;
            }
            xcnt++;
            s[i] = 'X';
        }
        dp = new int[vcnt + 1][kcnt + 1][xcnt + 1][3];
        for (int[][][] x : dp) {
            for (int[][] xx : x) {
                for (int[] xxx : xx) {
                    Arrays.fill(xxx, -1);
                }
            }
        }
        dp[0][0][0][0] = dp[0][0][0][1] = dp[0][0][0][2] = 0;
        int res = INF;
        for (int i = 0; i < 3; i++) {
            res = Math.min(res, solve(vcnt, kcnt, xcnt, i));
        }
        out.println(res);

    }

}


import java.util.Arrays;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int sum =0;
        int[] n = new int[a];
        for(int i = 0;i<a;i++){
            n[i] = sc.nextInt();
            sum+=n[i];
        }
        Arrays.sort(n);
        int i = 0;
        while(!check(sum,a)){
            sum+=5-n[i++];

        }
        System.out.println(i);
    }
    static boolean check(int sum,int n){

        return sum * 10 >= n * 45;
    }

}


import java.util.*;

import java.util.Collections;
import java.util.ArrayList;

public class javaapplication1 {

    public static final int MAX = 1000000007;

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

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

        int intX = in.nextInt();
        //long longX = (long)intX;
        int intY = in.nextInt();
        //long longY = (long)intY;

        //int[] arrDividendos = new int[intX];

        //No en Comun
        if (intY % intX != 0) {
            System.out.println(0);
        }else{
            intY = intY / intX;

        for (long i = 2; i * i <= intY; i++) {
            //Iniciar si es par
            if (intY % i == 0) {
                Dividendos.add((int) i);
            }
            //Es par pero no es el mismo numero
            if (intY % i == 0 && (intY / i != i)) {
                Dividendos.add(intY / (int) i);
            }
            /*
             if(intY % i == 0 && i !=intX){
                Dividendos.add(intY /x);
            }*/
        }

        if (intY != 1) {
            Dividendos.add(intY);
        } else {
            System.out.println(1);
            return;
        }

        int[] arrAnswer = new int[Dividendos.size()];
        long total = 0;
        Collections.sort(Dividendos);
        int temp = 0;
        for (int i = 0; i < arrAnswer.length; i++) {
            temp = (MAX + potencia(2, Dividendos.get(i) - 1,arrAnswer) - 1);
            //if(temp > intX){
            arrAnswer[i] = temp % MAX;
            //}
        }

        for (int i = 1; i < arrAnswer.length; i++) {
            for (int j = i - 1; j >= 0; j--) {
                if (Dividendos.get(i) % Dividendos.get(j) == 0) {
                    temp =(int) ((MAX + arrAnswer[i] - (long) arrAnswer[j])
                    arrAnswer[i] = temp % MAX);
                }
                 /*
                    if(intY % i == 0 && i !=intX){
                    Dividendos.add(intY /x);
                    }*/
            }
            total += arrAnswer[i];
            total = total % MAX;
        }
        System.out.println(arrAnswer[Dividendos.size() - 1]);
        }
    }

    public static int potencia(long x1, int x2, int[] intanswer) {
        long longI = 1;
        while (x2 >= 1) {
            if (x2 % 2 == 1) {
                longI = (longI * x1) % MAX;
            }
            x1 = (x1 * x1) % MAX;
            x2 = x2 /2;

        }
        //else
       //{break;
               // }
        return (int) longI;
    }

}


import java.util.*;
public class Stages{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		String s = sc.next();
		char a[] = s.toCharArray();
		Arrays.sort(a);
		int i = 1;
		char c = a[0];
		int cost = a[0]-'a'+1;
		for (int j=1;j<n;j++) {
			if (i>=k) {
				break;
			}
			if ((a[j]-c) > 1 ) {
				c = a[j];
				i++;
				cost += c-'a'+1;
			}

		}
		if (i!=k) {
			System.out.println("-1");
			break;
		}
		System.out.println(cost);
	}
}


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

public class HW504 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Integer n = sc.nextInt();
        int m = sc.nextInt();
        char[] c = new char[n];
        c =  n.toString().toCharArray();
        int count =0;
        int out = 0;
        if (c.length<m){
            System.out.println(c.length-1);
        }else{
            for(int i =c.length-1;i>=0;i-- ){
                if(c[i]=='0'){
                    count++;
                }else{
                    out++;
                }
                if (count==m){
                    break;
                }
            }
            System.out.println(out);
        }

    }
}


import java.util.Scanner;
import java.util.Arrays;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a[] = new int[n];
        int count =0;
        for(int i =0;i<n;i++){
            a[i]= sc.nextInt();
        }
        Arrays.sort(a);
        for(int i=0;i<n-1;i++){
            count += a[i+1]-a[i];
            i++;
        }
        Systm.out.println(count);
    }
}


import java.util.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.ArrayList;

public class kanbanNumbers
{
    private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    private long longVal() throws IOException {
        return Long.parseLong(br.readLine().trim());
    }

    private int intVal() throws IOException {
        return Integer.parseInt(br.readLine().trim());
    }

    private double doubleVal() throws IOException {
        return Double.parseDouble(br.readLine().trim());
    }

    private int[] intArr() throws IOException {
        String[] s = br.readLine().trim().split(" ");
        int n = s.length;
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = Integer.parseInt(s[i]);
        }
        return a;
    }

    private long[] longArr() throws IOException {
        String[] s = br.readLine().trim().split(" ");
        int n = s.length;
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = Long.parseLong(s[i]);
        }
        return a;
    }

    private double[] doubleArr() throws IOException {
        String[] s = br.readLine().trim().split(" ");
        int n = s.length;
        double[] a = new double[n];
        for (int i = 0; i < n; i++) {
            a[i] = Double.parseDouble(s[i]);
        }
        return a;
    }

    private String[] stringArr() throws IOException {
        String[] s = br.readLine().trim().split(" ");
        return s;
    }

    private char[] charArr() throws IOException {
        return br.readLine().trim().toCharArray();
    }

    public static String solve() throws IOException{
        kanbanNumbers obj = new kanbanNumbers();
        int n = obj.intVal();
        if(n<=12){
            if(n==1||n==7||n==9||n==10||n==11)
                return "NO";
            return "YES";
        }
        if(n<30)
            return "NO";
        if(n>=70 && n<=79)
            return "NO";
        if(n>=90 && n<=99)
            return "NO";
        n = n%10;
        if(n==1||n==7||n==9)
            return "NO";
        return "YES";
    }
    public static void kanbanNumbers(String[] args) throws IOException
    {
        kanbanNumbers ob = new kanbanNumbers();
//        int total_test_case = ob.intVal();
         int total_test_case = 1;
        StringBuffer ans = new StringBuffer();
        String k;
        for (int test_case = 0; test_case < total_test_case; test_case++) {
            k = ob.solve();
            // System.out.println(k);
            ans.append(k+"\n");
        }
        System.out.print(ans);
    }
}


import java.io.ByteArrayInputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

import live.ZZ;

import static java.lang.Math.*;

/*
 *
 * CFR 667, Div 2
 * https://codeforces.com/contest/1409
 *
 *
 *
 */
public class F_3 {

	public static void main(String[] args) throws Exception {
		new F_3().go();
	}
	static boolean LOCAL = System.getProperty("ONLINE_JUDGE") == null;

	Scanner in;
	//	String INPUT = "15 6\r\n" +
	//			"qwertyhgfdsazxc\r\n" +
	//			"qa";

	String INPUT = "	200 190\r\n" +
			"ghcebcdabheeeaeabfghdbegecabebhbahdhfchabchchbdcbcaebaebdbgebebhdadgegdahh"+
			"daaabehhgghchadfbggbgecahagdfceeffchfddecfgcdbbdhhecfhdfefdbeagcgaedahdebf"+
			"ffhecfcbbcdceghbfcggeaegcdhdchhebffhgchbgacddabcfbcg\r\n" +
			"	ha";

	//	String INPUT = "10 5   \n" +
	//			"qxaxxqxxqx        \n" +
	//			"qa";

	void go() {
		if (LOCAL) {
			System.setIn(new ByteArrayInputStream(INPUT.getBytes()));
		}
		in = new Scanner(System.in);
		long startTime = System.currentTimeMillis();
		solve();
		if (LOCAL) {
			System.out.printf("[%dms]", System.currentTimeMillis()-startTime);
		}
		in.close();
	}

	PrintWriter out = new PrintWriter(System.out);

	void solve() {
		solve2(1);
		out.flush();
	}

	// int inf = (int) 1e9;

	void solve2(int caseNr) {
		int n = in.nextInt();
		int k = in.nextInt();
		String s_str = in.next();
		String t_str = in.next();
		char[] s = s_str.toCharArray();
		char[] t = t_str.toCharArray();

		int[][][] dp = new int[n+1][k+1][n+1];

		for (int i = 0; i < n+1; i++) {
			for (int j = 0; j < k+1; j++) {
				Arrays.fill(dp[i][j], -1);
			}
		}

		dp[0][0][0] = 0;

		for (int i = 0; i < n; i++) {
			for (int ck = 0; ck <= k; ck++) {
				for (int ct0 = 0; ct0 <= n; ct0++) {
					if (dp[i][ck][ct0] == -1) continue;
					int e0 = s[i] == t[0] ? 1 : 0;
					int e1 = s[i] == t[1] ? 1 : 0;
					int e01 = t[0] == t[1] ? 1 : 0;

					dp[i + 1][ck][ct0 + e0] = max(dp[i + 1][ck][ct0 + e0], dp[i][ck][ct0] + (e1==1 ? ct0 : 0));

					if (ck < k) {
						dp[i + 1][ck + 1][ct0 + 1] = max(dp[i + 1][ck + 1][ct0 + 1], dp[i][ck][ct0] + (e01==1 ? ct0 : 0));
						dp[i + 1][ck + 1][ct0 + e01] = max(dp[i + 1][ck + 1][ct0 + e01], dp[i][ck][ct0] + ct0);
					}

				}
			}
		}

		int ans = 0;
		for (int ck = 0; ck <= k; ck++) {
			for (int ct0 = 0; ct0 <= n; ct0++) {
				ans = max(ans, dp[n][ck][ct0]);
			}
		}

		//		System.out.printf("dp[1][0][0] = %d \n", dp[1][0][0]);
		//		System.out.printf("dp[1][0][1] = %d \n", dp[1][0][1]);
		//		System.out.printf("dp[1][1][0] = %d \n", dp[1][1][0]);
		//		System.out.printf("dp[1][1][1] = %d \n", dp[1][1][1]);

		// ZZ.showIntegerArray(dp[0]);

		System.out.println(ans);
	} // end of solve2

}


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

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

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] a = new int[n];
            for (int i = 0; i < n; ++i) {
                a[i] = in.nextInt();
            }
            for (int i = 0; i < (1 << n); ++i) {
                int t = 0;
                for (int j = 0; j < n; ++i) {
                    if ((i & (1 << j)) == 1) t += a[j];
                    else t -= a[j];
                }
                if (t % 360 == 0) {
                    out.println("YES");
                    return;
                }
            }
            out.println("NO");
        }

    }

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

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

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

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

    }
}


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

public class Main {

    static int n, m, k;

    public static void main(String[] args) {
        IO io = new IO();
        n = io.nextInt();
        m = io.nextInt();
        k = io.nextInt();

        int[][][] b = new int[n + 100][m + 100][k + 100];

        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= m; j++) {
                for (int kk = 0; kk <= k; kk++) {
                    if (kk == 0){ b[i][j][kk] = i * j;continue;}
                     if (i - 1 + j - 1 < kk) {b[i][j][kk] = -1;continue;}
                    if (i - 1 + j - 1 == kk) {b[i][j][kk] = 1;continue;}

                    for (int i0 = 1; i0 <= i - 1; i0++) {
                        b[i][j][kk] = Math.max(b[i][j][kk], Math.min(i0 * j, b[i - i0][j][kk - 1]));
                    }
                    for (int j0 = 1; j0 <= j - 1; j0++) {
                        b[i][j][kk] = Math.max(b[i][j][kk], Math.min(j0 * i, b[i][j - j0][kk - 1]));
                    }
                }
            }
        }
        io.println(b[n][m][k]);
    }

    static class IO {

        BufferedInputStream din;
        final int BUFFER_SIZE = 1 << 16;
        byte[] buffer;
        int byteRead, bufferPoint;

        StringBuilder builder;
        PrintWriter pw;

        public IO() {
            din = new BufferedInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPoint = byteRead = 0;

            builder = new StringBuilder();
            pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
                    System.out
            )), true);
        }

        int read() {
            if (bufferPoint >= byteRead) {
                try {
                    byteRead = din.read(buffer, bufferPoint = 0, BUFFER_SIZE);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (byteRead == -1) buffer[0] = -1;
            }
            return buffer[bufferPoint++];
        }

        int peek() {
            if (byteRead == -1) return -1;
            if (bufferPoint >= byteRead) {
                try {
                    byteRead = din.read(buffer, bufferPoint = 0, BUFFER_SIZE);
                } catch (IOException e) {
                    return -1;
                }
                if (byteRead <= 0) return -1;
            }
            return buffer[bufferPoint];
        }

        boolean hasNext() {
            int c = peek();
            while (c != -1 && c <= ' ') {
                read();
                c = peek();
            }
            return c != -1;
        }

        char nextChar() {
            int c = read();
            while (c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1) {
                c = read();
            }
            return (char) c;
        }

        double nextDouble() {
            double ret = 0, div = 1;
            int 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;
        }

        String nextLine() {
            byte[] strBuf = new byte[64];
            int cnt = 0, c;
            while ((c = read()) != -1) {
                if (c == '\n') {
                    if (cnt == 0) {
                        continue;
                    } else {
                        break;
                    }
                }
                if (strBuf.length == cnt) {
                    strBuf = Arrays.copyOf(strBuf, strBuf.length * 2);
                }
                strBuf[cnt++] = (byte) c;
            }
            return new String(strBuf, 0, cnt);
        }

        String next() {
            byte[] strBuf = new byte[64];
            int cnt = 0, c;
            while ((c = read()) != -1) {
                if (Character.isWhitespace(c)) {
                    if (cnt == 0) {
                        continue;
                    } else {
                        break;
                    }
                }
                if (strBuf.length == cnt) {
                    strBuf = Arrays.copyOf(strBuf, strBuf.length * 2);
                }
                strBuf[cnt++] = (byte) c;
            }
            return new String(strBuf, 0, cnt);
        }

        int nextInt() {
            int ans = 0;
            int c = read();
            while (c <= ' ') c = read();
            boolean neg = (c == '-');
            if (neg) c = read();
            do {
                ans = ans * 10 + c - '0';
            } while ('0' <= (c = read()) && c <= '9');
            bufferPoint--;
            return neg ? -ans : ans;
        }

        long nextLong() {
            long ans = 0;
            int c = read();
            while (c <= ' ') c = read();
            boolean neg = (c == '-');
            if (neg) c = read();
            do {
                ans = ans * 10 + c - '0';
            } while ('0' <= (c = read()) && c <= '9');
            bufferPoint--;
            return neg ? -ans : ans;
        }

        void println(Object o) {
            pw.println(o);
        }

        void print(Object o) {
            pw.print(o);
        }

        void printf(String format, Object... objects) {
            pw.printf(format, objects);
        }

        void close() {
            pw.close();
        }

        void done(Object o) {
            print(o);
            close();
        }

    }
}


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

public class Main {

	 static int INF=1<<28;
	//int x,y;
	//static int sum=0;

	static ArrayList<Integer> lis = new ArrayList<Integer>();
	public static void main(String[] args)throws Exception{
	//	Scanner sc =new Scanner(new File("input.txt"));
		Scanner sc =new Scanner(System.in);
    //  File file = new File("output.txt");
	//	PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(file)));
	//	sc.useDelimiter("(\\s)+|[,]");
	//	ArrayList<Integer> lis = new ArrayList<Integer>();
    //  for(int i=0;i<;i++)

	while(sc.hasNext()){
		int a=ni(sc),b=ni(sc);
	int l=1;
	ArrayList<Integer> lis = new ArrayList<Integer>();
	for(int i=0;i<b-1;i++)l*=10;
 lp:	for(int i=l;i<(b+1)*l;i++){
		ArrayList<Character> cs = new ArrayList<Character>();
	  String x=String.valueOf(i);
	  for(int t=1;t<=b;t++){char cc=x.charAt(t-1);
	  if(cc=='0' ||cs.contains(cc) || 49+b <=(int)cc)continue lp;else cs.add(cc);  }
		lis.add(i);
	}

	String s[]=new String[a];
	 for(int i=0;i<a;i++)s[i]=sc.next();
	int r=99999999;
	 for(int i=0;i<lis.size();i++){
		 int min=99999999,max=0;

		 for(int j=0;j<a;j++){
			 int f=lis.get(i);
		 String ss="";
		 for(int t=0;t<b;t++){int h=f%10-1; ss+=s[j].substring(h,h+1);f/=10;  }
		 int kk=Integer.parseInt(ss);

		 min=min(kk,min);
		 max=max(max,kk);
		 }
		 r=min(r,max-min);
	 }
	 System.out.println(r);

	    }

	}

	static void db(Object... os){
	         System.err.println(Arrays.deepToString(os));

	}

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

}


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

public class CodeForces {

    private List<String> getPermutation(final String str) {
        if(str.length() == 1) {
            List<String> ret = new LinkedList<String>();
            ret.add(str);
            return ret;
        }
        List<String> tmp = getPermutation(str.substring(1));
        List<String> ret = new LinkedList<String>();
        for(final String s : tmp) {
            for(int i = 0; i < s.length() + 1; i++) {
                final String head = s.substring(0, i);
                final String tail = s.substring(i);
                ret.add(head + str.charAt(0) + tail);
            }
        }
        return ret;
    }

    private void solve() throws IOException {
        int n = nextInt(), k = nextInt();
        List<String> li = new LinkedList<String>();
        for(int i = 0; i < n; i++)
            li.add(nextLine());
        List<List<Integer>> perms = new LinkedList<List<Integer>>();
        for(int i = 0; i < n; i++) {
            final List<String> p = getPermutation(li.get(i));
            List<Integer> tmp = new LinkedList<Integer>();
            for(final String ss : p)
                tmp.add(Integer.parseInt(ss, 10));
            perms.add(tmp);
        }
        int ret = Integer.MAX_VALUE;
        for(int j = 0; j < perms.get(0).size(); j++) {
            int max = Integer.MIN_VALUE, min = Integer.MAX_VALUE;
            for(int l = 0; l < perms.size(); l++) {
                max = Math.max(perms.get(l).get(j), max);
                min = Math.min(perms.get(l).get(j), min);
            }
            ret = Math.min(ret, max - min);
        }
        System.out.println(ret);
    }

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

    BufferedReader reader;
    StringTokenizer tokenizer;
    PrintWriter writer;

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

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


import java.io.OutputStreamWriter;
import java.io.BufferedWriter;
import java.util.Comparator;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.Collection;
import java.util.List;
import java.io.IOException;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.ArrayList;
import java.math.BigInteger;
import java.io.InputStream;

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

class TaskE {
	String numbers = "1 1\n" +
		"2 2\n" +
		"3 4\n" +
		"4 6\n" +
		"5 12\n" +
		"6 24\n" +
		"7 36\n" +
		"8 48\n" +
		"9 60\n" +
		"10 120\n" +
		"11 180\n" +
		"12 240\n" +
		"13 360\n" +
		"14 720\n" +
		"15 840\n" +
		"16 1260\n" +
		"17 1680\n" +
		"18 2520\n" +
		"19 5040\n" +
		"20 10080\n" +
		"21 15120\n" +
		"22 25200\n" +
		"23 27720\n" +
		"24 55440\n" +
		"25 110880\n" +
		"26 166320\n" +
		"27 277200\n" +
		"28 332640\n" +
		"29 554400\n" +
		"30 665280\n" +
		"31 720720\n" +
		"32 1441440\n" +
		"33 2162160\n" +
		"34 3603600\n" +
		"35 4324320\n" +
		"36 7207200\n" +
		"37 8648640\n" +
		"38 10810800\n" +
		"39 21621600\n" +
		"40 36756720";

	public void solve(int testNumber, InputReader in, OutputWriter out) {
		numbers = numbers.replace('\n', ' ');
		String[] tokens = numbers.split(" ");
		int index = in.readInt();
		out.printLine(IntegerUtils.power(2, Integer.parseInt(tokens[2 * index - 1]), 1000000007) - 1);
	}
}

class InputReader {

	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;
	private 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 readInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

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

class OutputWriter {
	private final PrintWriter writer;

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

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

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

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

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

	}

class IntegerUtils {

    public static long power(long base, long exponent, long mod) {
		if (exponent == 0)
			return 1;
		long result = power(base, exponent >> 1, mod);
		result = result * result % mod;
		if ((exponent & 1) != 0)
			result = result * base % mod;
		return result;
	}

	}


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

public class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
	    Scanner in =new Scanner(System.in);
	    int n=in.nextInt();
	    int m=in.nextInt();
	    Pair p[] = new Pair[n];
	    Pair pp[] = new Pair[m];
	    for(int i=0;i<n;i++){
	        p[i] = new Pair(in.nextInt(),in.nextInt());
	    }
	    for(int i=0;i<m;i++){
	        pp[i] = new Pair(in.nextInt(),in.nextInt());
	    }
	    Map<Pair,Integer> map = new HashMap<Pair,Integer>();
	    for(int i=0;i<n;i++){
	        for(int j=0;j<m;j++){
	            int t = p[i].singleCommon(pp[j]);
	            if(t!=-1){
	                if(map.containsKey(p[i])){
	                    if(map.get(p[i])!=t){
	                        System.out.println(-1);
	                        return;
	                    }
	                }
	                else{
	                    map.put(p[i],t);
	                }
	            }
	        }
	    }
	    if(map.keySet().size()==0){
	        System.out.println(-1);
	    }
	    else if(map.keySet().size()==1){
	        for(int i:map.values()){
	            System.out.println(i);
	        }
	    }
	    else{
	        if(map.values().size()==1){
	            for(int i:map.values()){
	            System.out.println(i);
	        }
	        }
	        else{
	            System.out.println(0)
	        }
	    }
	}
}
class Pair{
    int x,y;
    public Pair(int x, int y){
        this.x = x;
        this.y =y;
    }
    public int singleCommon(Pair p){
        if((p.x==x&&p.y!=y)||(p.x==y&&p.y!=x)||(p.x!=x&&p.y==y)||(p.x!=y&&p.y==x)){
            return p.x==x?x:y;
        }
        return -1;
    }
}


import java.util.*;
public class Soution{
    public static void main(String[] args){
        int n=sc.nextInt();
        for(int i=2;i<=n;i++){
            if(n%i==0){
                System.out.println(i+""+n/i);
                return;
            }
        }
    }
}