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

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

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

	void run() {
		try {
			br = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			solve();
		} catch (Throwable e) {
			e.printStackTrace();
			System.exit(-1);
		} finally {
			out.close();
		}
	}

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

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

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

	int calc(int[] v) {
		Arrays.sort(v);
		if (v[0] % 2 == v[1] % 2) {
			return v[1];
		} else {
			return v[2];
		}
	}

	int[][][] map = new int[100][100][100];

	int trueCalc(int[] v) {
		Arrays.sort(v);
		if (v[1] == 0) return 0;
		if (map[v[0]][v[1]][v[2]] != 0) {
			return map[v[0]][v[1]][v[2]];
		}
		int ans = Integer.MAX_VALUE;
		for (int i = 0; i < 3; ++i) {
			int j = (i + 1) % 3;
			if (v[i] > 0 && v[j] > 0) {
				int[] w = v.clone();
				--w[i];
				--w[j];
				++w[3 - i - j];
				ans = Math.min(ans, trueCalc(w) + 1);
			}
		}
		map[v[0]][v[1]][v[2]] = ans;
		return ans;
	}

	void solve() throws IOException {

/*		for (int i = 0; i < 10; ++i) {
			for (int j = 0; j < 10; ++j) {
//				System.out.println(i + " " + j);
				for (int k = 0; k < 10; ++k) {
					int[] w = {i, j, k};
					int a1 = calc(w);
					int a2 = trueCalc(w);
					if (a1 != a2) {
						System.err.println(Arrays.toString(w));
					}
				}
			}
		}
*/
		int[] v = new int[3];
		for (int i = 0; i < v.length; ++i) {
			v[i] = nextInt();
		}
		out.println(calc(v));
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashSet;

public class D {

//    static void build_tree(int n) {
//        int[] cnt=new int[n];
//        int[][] left=new int[n][n<<5], right=new int[n][n<<5];
//
//        cnt[0]=1;
//        for (int level=0; level<n-1; level++) {
//            cnt[level+1]=0;
//            for (int position=1; position<=cnt[level]; position++) {
//                if (Integer.bitCount(position)==1) { // то есть 1, 2, 4, 8...
//                    left[level][position]=cnt[level+1]+1;
//                    right[level][position]=cnt[level+1]+2;
//                    cnt[level+1]=cnt[level+1]+2;
//                } else {
//                    right[level][position]=cnt[level+1]+1;
//                    cnt[level+1]=cnt[level+1]+1;
//                }
//            }
//        }
//
//        int total=0;
//        for (int i=0; i<n; i++) {
//            total+=cnt[i];
//        }
//
//        System.out.println(total);
//    }

    static int log2(int i) {
        int ret=0;
        while(i>0) {
            ret++;
            i=i>>1;
        }
        return ret;
    }

    static void compute(int n, int[][] q) {
        //group queries by level
        int[] l2qcnt=new int[n+1];
        for (int i=0; i<q.length; i++) {
            if(q[i][0]==1) {
                l2qcnt[q[i][1]]++;
            }
        }
        int[][] l2q=new int[n+1][];
        for (int i=1; i<=n; i++) {
            l2q[i]=new int[l2qcnt[i]];
        }
        Arrays.fill(l2qcnt, 0);
        //end group queries by level

        HashSet<Integer> s=new HashSet<Integer>();
        for (int i=0; i<q.length; i++) {
            int lvl=q[i][1];
            if(q[i][0]==1) {
                l2q[lvl][l2qcnt[lvl]++]=i;
            } else {
                s.clear();
                int l=q[i][2], r=l;
                for (int j=lvl; j<=n; j++) {
                    for (int k=0; k<l2qcnt[j]; k++) {
                        int qidx=l2q[j][k];
                        int ql=q[qidx][2];
                        int qr=q[qidx][3];
                        if(!(r<ql||l>qr)) {
                            s.add(q[qidx][4]);
                        }
                    }
                    //update l,r
                    int extra=Integer.bitCount(r)==1? 1: 0;
                    l+=log2(l-1);
                    r+=log2(r-1);
                    r+=extra;
                }
                System.out.println(s.size());
            }
        }
    }

    static StringBuilder sb=new StringBuilder();
    static void parse(String l, int[] here) {
        sb.setLength(0);
        int len=l.length(), j=0;
        for (int i=0; i<len; i++) {
            char c=l.charAt(i);
            if(c==' ') {
                here[j++]=Integer.parseInt(sb.toString());
                sb.setLength(0);
            } else {
                sb.append(c);
            }
        }
        if(sb.length()>0) {
            here[j++]=Integer.parseInt(sb.toString());
        }
    }

    static void run_stream(InputStream ins) throws IOException {
        BufferedReader r=new BufferedReader(new InputStreamReader(System.in));
        String[] l=r.readLine().split(" ");
        int n=Integer.parseInt(l[0]);
        int m=Integer.parseInt(l[1]);

        int[][] q=new int[m][5];
        for (int i=0; i<m; i++) {
            parse(r.readLine(), q[i]);
            //q[i][1]--;
        }

        compute(n, q);
    }

    public static void main(String[] args) throws IOException {
        run_stream(System.in);
    }
}


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

public class B {
	public static void main(String[] args) throws Exception {
		new B().solve();
		// new FileInputStream(new File("input.txt")),
		// new PrintStream(new FileOutputStream(new File("output.txt"))));
	}

	void solve() throws IOException {
		BufferedReader in = new BufferedReader(new
				InputStreamReader(System.in));
		Scanner sc = new Scanner(System.in);
		String[] sp;

		// n, m
		sp = in.readLine().split(" ");
		int n = Integer.parseInt(sp[0]);
		int m = Integer.parseInt(sp[1]);

		// par
		int[] par = new int[140000];
		{
			int nci = 1;
			for (int pos = 1; nci < par.length; pos++) {
				if ((pos & -pos) == pos) {// 2^k
					par[nci++] = pos;
					par[nci++] = pos;
				} else {
					par[nci++] = pos;
				}
			}
		}

		ArrayList<Integer> level = new ArrayList<Integer>();
		ArrayList<Integer> left = new ArrayList<Integer>();
		ArrayList<Integer> right = new ArrayList<Integer>();
		ArrayList<Integer> x = new ArrayList<Integer>();
		ArrayList<Integer[][]> lvLR = new ArrayList<Integer[][]>();
		HashSet<Integer> set = new HashSet<Integer>();
		StringBuilder sb = new StringBuilder();
		// operations
		for (int i = 0; i < m; i++) {
			sp = in.readLine().split(" ");
			int op = Integer.parseInt(sp[0]);
			if (op == 1) {
				int lv, l, r;
				level.add(lv = Integer.parseInt(sp[1]));
				left.add(l = Integer.parseInt(sp[2]));
				right.add(r = Integer.parseInt(sp[3]));
				x.add(Integer.parseInt(sp[4]));
				Integer[][] lr = new Integer[n + 1][2];
				lvLR.add(lr);

				for (int jj = n; jj > lv; jj--) {
					lr[jj][0] = lr[jj][1] = -1;
				}
				lr[lv][0] = l;
				lr[lv][1] = r;
				for (int jj = lv - 1; jj >= 1; jj--) {
					lr[jj][0] = par[lr[jj + 1][0]];
					lr[jj][1] = par[lr[jj + 1][1]];
				}

			} else {// 2
				int lv = Integer.parseInt(sp[1]);
				int p = Integer.parseInt(sp[2]);
				set.clear();

				for (int ai = 0; ai < level.size(); ai++) {
					Integer[][] lr = lvLR.get(ai);
					if (lr[lv][0] != -1) {
						if (lr[lv][0] <= p && p <= lr[lv][1]) {
							set.add(x.get(ai));
						}
					}
				}
				sb.append(set.size() + "\n");
			}
		}
		System.out.print(sb);
	}
}
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//


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

public class B {
    public static void main(String[] args) throws Exception {
        new B().solve();
        // new FileInputStream(new File("input.txt")),
        // new PrintStream(new FileOutputStream(new File("output.txt"))));
    }

    void solve() throws IOException {
        BufferedReader in = new BufferedReader(new
                InputStreamReader(System.in));
        Scanner sc = new Scanner(System.in);
        String[] sp;

        // n, m
        sp = in.readLine().split(" ");
        int n = Integer.parseInt(sp[0]);
        int m = Integer.parseInt(sp[1]);

        // par
        int[][] par = new int[n][1000000];
        {
            // 0
            for (int pos = 1; pos < par[0].length; pos++) {
                par[0][pos] = pos;
            }
            // 1
            int nci = 1;
            for (int pos = 1; nci < par[0].length; pos++) {
                if ((pos & -pos) == pos) {// 2^k
                    par[1][nci++] = pos;
                    par[1][nci++] = pos;
                } else {
                    par[1][nci++] = pos;
                }
            }
            // 2~
            for (int lv = 2; lv < n; lv++) {
                for (int pos = 1; pos < par[0].length; pos++) {
                    par[lv][pos] = par[1][par[lv - 1][pos]];
                }
            }
        }

        ArrayList<Integer> level = new ArrayList<Integer>();
        ArrayList<Integer> left = new ArrayList<Integer>();
        ArrayList<Integer> right = new ArrayList<Integer>();
        ArrayList<Integer> x = new ArrayList<Integer>();
        HashSet<Integer> set = new HashSet<Integer>();
        // operations
        for (int i = 0; i < m; i++) {
            sp = in.readLine().split(" ");
            int op = Integer.parseInt(sp[0]);
            if (op == 1) {
                level.add(Integer.parseInt(sp[1]));
                left.add(Integer.parseInt(sp[2]));
                right.add(Integer.parseInt(sp[3]));
                x.add(Integer.parseInt(sp[4]));
            } else {// 2
                int lv2 = Integer.parseInt(sp[1]);
                int p = Integer.parseInt(sp[2]);
                set.clear();

                for (int ai = 0; ai < level.size(); ai++) {
                    int lv1 = level.get(ai);
                    if (lv2 <= lv1) {
                        int l = par[lv1 - lv2][left.get(ai)];
                        int r = par[lv1 - lv2][right.get(ai)];
                        if (l <= p && p <= r) {
                            set.add(x.get(ai));
                        }
                    }
                }
                System.out.println(set.size());
            }
        }
    }
}
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//


import static java.lang.Integer.*;

import java.util.*;

//@SuppressWarnings("unused")
public class B {

	private final static boolean autoflush = false;

	Random R = new Random();

	class Segment implements Comparable<Segment> {
		int L, R;
		Set<Integer> H = new TreeSet<>();
		public boolean equals(Object o) {
			Segment s = (Segment)o;
			return s.L == L && s.R == R;
		}
		public int compareTo(Segment s) {
			if (L != s.L) return L - s.L;
			else return R - s.R;
		}
	}

	public B () {
		int SZ = 200000;
		int [] P = new int [SZ];
		for (int i = 1, s = 1; i < SZ; ++i, ++s) {
			P[i] = s;
			if (bitCount(s) == 1)
				P[++i] = s;
		}

		int N = sc.nextInt();
		int M = sc.nextInt();

		TreeMap<Segment, Segment> [] L = new TreeMap[N+1];
		for (int i = 1; i <= N; ++i)
			L[i] = new TreeMap<Segment, Segment>();

		for (int m = 0; m < M; ++m) {
			Integer [] Q = sc.nextInts();
			if (Q[0] == 1) {
				int t = Q[1], l = Q[2], r = Q[3], x = Q[4];
				for (int y = t; y >= 1; --y) {
					Segment S = new Segment(); S.L = l; S.R = r;
					if (L[y].containsKey(S))
						L[y].get(S).H.add(x);
					else {
						S.H.add(x);
						L[y].put(S, S);
					}
					l = P[l]; r = P[r];
				}
			} else {
				Set<Integer> res = new TreeSet<Integer>();
				int t = Q[1], v = Q[2];
				for (Segment S : L[t].keySet())
					if (S.L <= v && S.R >= v)
						res.addAll(S.H);
				print(res.size());
			}
		}
	}

	////////////////////////////////////////////////////////////////////////////////////
	private final static MyScanner sc = new MyScanner();
	private static class MyScanner {
		public String next() { newLine(); return line[index++]; }
		public int nextInt() { return Integer.parseInt(next()); }
		public String nextLine() { line = null; return readLine(); }
		public String [] nextStrings() { return nextLine().split(" "); }
		public Integer [] nextInts() {
			String [] L = nextStrings();
			Integer [] res = new Integer [L.length];
			for (int i = 0; i < L.length; ++i)
				res[i] = Integer.parseInt(L[i]);
			return res;
		}
		//////////////////////////////////////////////
		private boolean eol() { return index == line.length; }
		private String readLine() {
			try {
				return r.readLine();
			} catch (Exception e) {
				throw new Error (e);
			}
		}
		private final java.io.BufferedReader r;
		private MyScanner () { this(new java.io.BufferedReader(new java.io.InputStreamReader(System.in))); }
		private MyScanner (java.io.BufferedReader r) {
			try {
				this.r = r;
				while (!r.ready())
					Thread.sleep(1);
				start();
			} catch (Exception e) {
				throw new Error(e);
			}
		}
		private String [] line;
		private int index;
		private void newLine() {
			if (line == null || eol()) {
				line = readLine().split(" ");
				index = 0;
			}
		}
	}
	private static void print (Object o, Object... a) { printDelim(" ", o, a); }
	private static void printDelim (String delim, Object o, Object... a) { pw.println(build(delim, o, a)); }
	private static void exit() {
		pw.close();
		System.out.flush();
		System.err.println("------------------");
		System.err.println("Time: " + ((millis() - t) / 1000.0));
		System.exit(0);
	}
	////////////////////////////////////////////////////////////////////////////////////
	private static String build (String delim, Object o, Object... a) {
		StringBuilder b = new StringBuilder();
		append(b, o, delim);
		for (Object p : a)
			append(b, p, delim);
		return b.substring(delim.length());
	}
	private static void append(StringBuilder b, Object o, String delim) {
		if (o.getClass().isArray()) {
			int L = java.lang.reflect.Array.getLength(o);
			for (int i = 0; i < L; ++i)
				append(b, java.lang.reflect.Array.get(o, i), delim);
		} else if (o instanceof Iterable<?>)
			for (Object p : (Iterable<?>)o)
				append(b, p, delim);
		else
			b.append(delim).append(o);
	}
	////////////////////////////////////////////////////////////////////////////////////
	private static void start() { t = millis(); }
	private static java.io.PrintWriter pw = new java.io.PrintWriter(System.out, autoflush);
	private static long t;
	private static long millis() { return System.currentTimeMillis(); }
	public static void main (String[] args) { new B(); exit(); }
}


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

public class HappyNumbers implements Runnable {
    private void solve() throws IOException {
        /*for (long l = 1; l <= 1000; ++l) {
            System.out.println(l);
            for (long a = 1; a <= 1000; ++a) {
                if (doit(a, l) != doit2(a, l))
                    throw new RuntimeException(a + " " + l);
            }
        }*/
        long a = nextLong();
        long l = nextLong();
        System.out.println(doit(a, l));
    }

    /*private long doit2(long a, long l) {
        for (long b = a + 1;; ++b) {
            boolean ok = true;
            for (int i = 0; i < l; ++i)
                if (countLucky(a + i) != countLucky(b + i)) {
                    ok = false;
                    break;
                }
            if (ok)
                return b;
        }
    }*/

    private long doit(long a, long l) {
        if (l >= 10) {
            long first = a;
            long last = a + l - 1;
            return doit(first / 10, last / 10 - first / 10 + 1) * 10 + first % 10;
        } else {
            int[] cnts = new int[(int) l];
            for (int i = 0; i < l; ++i)
                cnts[i] = countLucky(a + i);
            return doitFrom(cnts, a + 1);
        }
    }

    private long doitFrom(int[] cnts, long min) {
        if (cnts.length == 1) {
            return doitOne(cnts[0], min);
        } else if (cnts.length == 2 && min <= 1) {
            return doitTwoSimple(cnts[0], cnts[1], min);
        }
        long res = Long.MAX_VALUE;
        for (int lastDigit = 0; lastDigit < 10; ++lastDigit) {
            int max = lastDigit + cnts.length - 1;
            int[] ncnts = new int[max / 10 + 1];
            Arrays.fill(ncnts, -1);
            boolean ok = true;
            for (int i = 0; i < cnts.length; ++i) {
                int cur = lastDigit + i;
                int need = cnts[i];
                if (cur % 10 == 4 || cur % 10 == 7)
                    --need;
                if (need < 0) {
                    ok = false;
                    break;
                }
                if (ncnts[cur / 10] < 0 || ncnts[cur / 10] == need) {
                    ncnts[cur / 10] = need;
                } else {
                    ok = false;
                    break;
                }
            }
            if (!ok) continue;
            long newMin = min / 10 - 3;
            while (newMin * 10 + lastDigit < min)
                ++newMin;
            long tmp = doitFrom(ncnts, newMin) * 10 + lastDigit;
            res = Math.min(res, tmp);
        }
        return res;
    }

    private long doitTwoSimple(int cntFirst, int cntSecond, long min) {
        if (cntFirst == 0 && cntSecond == 0)
            return min;
        if (cntFirst == cntSecond) {
            long res = 0;
            for (int i = 0; i < cntFirst; ++i)
                res = res * 10 + 4;
            return res * 10;
        } else if (cntFirst == cntSecond + 1) {
            long res = 0;
            for (int i = 0; i < cntFirst; ++i)
                res = res * 10 + 4;
            return res;
        } else if (cntFirst + 1 == cntSecond) {
            long res = 0;
            for (int i = 0; i < cntSecond; ++i)
                res = res * 10 + 4;
            return res - 1;
        } else {
            return Long.MAX_VALUE;
        }
    }

    private long doitOne(int cnt, long min) {
        long p10 = 1;
        int pow = 0;
        while (p10 <= min) {
            p10 *= 10;
            ++pow;
        }
        p10 *= 100;
        pow += 2;
        while (pow < cnt + 2) {
            p10 *= 10;
            ++pow;
        }
        long res = 0;
        while (true) {
            for (int curDigit = 0; curDigit < 10; ++curDigit) {
                int curCnt = 0;
                if (curDigit == 4 || curDigit == 7) curCnt = 1;
                if (possible(res, p10, pow, cnt - curCnt, min)) {
                    cnt -= curCnt;
                    break;
                }
                res += p10;
                if (curDigit == 9)
                    throw new RuntimeException();
            }
            if (p10 == 1) break;
            p10 /= 10;
            --pow;
        }
        return res;
    }

    private boolean possible(long res, long p10, int pow, int needLucky, long min) {
        if (needLucky > pow || needLucky < 0)
            return false;
        long cur = 0;
        for (int i = 0; i < pow - needLucky; ++i)
            cur = cur * 10 + 9;
        for (int i = 0; i < needLucky; ++i)
            cur = cur * 10 + 7;
        return res + cur >= min;
    }

    private int countLucky(long x) {
        int res = 0;
        while (x > 0) {
            long dig = x % 10;
            x /= 10;
            if (dig == 4 || dig == 7) ++res;
        }
        return res;
    }

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

    BufferedReader reader;
    StringTokenizer tokenizer;
    PrintWriter writer;

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

    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 nextToken() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }
}


import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
public class Main {
    public static void main(String[]args){
    new Main().run();
    }
    void run(){
    Scanner sc=new Scanner(System.in);
    long a=sc.nextLong(),l=sc.nextLong()-1;
    long res=func(a,l);
    System.out.println(res);
    }
    private long func(long a,long l){// [a,a+l]
    if(l>20){
        return a%10 + func(a/10,l/10 + (a%10+l%10)/10)*10;
    }
    int[] cnt=new int[(int)(l+1)];
    for (int i = 0; i<l+1; i++){
        cnt[i]=lucky(a+i);
    }
    return func2(a+1,cnt);
    }
    private int lucky(long l) {
    int res=0;
    while(l>0){
        if(l%10==4||l%10==7)res++;
        l/=10;
    }
    return res;
    }
    long INF=1L<<58;
    class E{
    long min;
    int[] cnt;
    E(long min,int[] cnt){
        this.min=min;
        this.cnt=cnt;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj==null) return false;
        if (getClass()!=obj.getClass()) return false;
        final E other = (E) obj;
        if (this.min!=other.min) return false;
        if (!Arrays.equals(this.cnt, other.cnt)) return false;
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 67*hash+(int) (this.min^(this.min>>>32));
        hash = 67*hash+Arrays.hashCode(this.cnt);
        return hash;
    }

    }
    HashSet<E> set=new HashSet<E>();
    private long func2(long min, int[] cnt) {
    if(cnt.length==1){
        return func3(min,cnt[0]);
    }
    E key = new E(min,cnt);
    if(set.contains(key))return INF;
    set.add(key);
    long res=INF;
    loop:for (int o = 0; o<10; o++) {
        int i=(int)((min+o)%10);
        int len = (i+cnt.length-1)/10 + 1;
        int[] ncnt=new int[len];
        fill(ncnt,-1);
        len=0;
        for (int j = 0; j<cnt.length; j++) {
        int tmp = cnt[j] - lucky((i+j)%10);
        if(tmp<0 || ncnt[len]!=-1 && ncnt[len]!=tmp)continue loop;
        ncnt[len]=tmp;
        if((i+j)%10==9)len++;
        }
        long tmp2=func2(min/10 + (i<min%10 ? 1:0), ncnt);
        res=min(tmp2*10+i,res);
    }
    return res;
    }

    private long func3(long min, int cnt) {
    long p10=1;
    int dig=1;
    while(p10<min || dig<cnt){
        p10*=10;
        dig++;
    }
    long res=0;
    while(dig>0){
        for (int i = 0;; i++) {
        long tmp = res + p10 * i;
        if(possible(tmp,min,p10/10,dig-1,cnt)){
            res=tmp;break;
        }
        if(i==9)throw new RuntimeException();
        }
        p10/=10;
        dig--;
    }
    return res;
    }

    private boolean possible(long tmp, long min,long p10, int dig, int cnt) {
    if(lucky(tmp) > cnt)return false;
    cnt -= lucky(tmp);
    if(cnt>dig)return false;
    while(cnt<dig){
        tmp += p10*9;
        dig--;
        p10/=10;
    }
    while(dig>0){
        tmp += p10*7;
        dig--;
        p10/=10;
    }
    return tmp>=min;
    }
}


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

public class Main{
    static void debug(Object...os){
        System.err.println(deepToString(os));
    }

    void run(){

    //      Random r=new Random();
    //      for(int o=0;o<1000000;o++) {
    //          System.out.print(".");
    //          long start=System.currentTimeMillis();
    ////            int a=r.nextInt(1000000000),l=r.nextInt(10);
    //          int a=777777770,l=9129;
    //          long res = calc(a,l);
    //          assert a<res;
    //          for(int i=0;i<l;i++) {
    //              int cnt=0;
    //              long t=res+i;
    //              while(t>0) {
    //                  if(t%10==4 || t%10==7)cnt++;
    //                  t/=10;
    //              }
    //              t=a+i;
    //              while(t>0) {
    //                  if(t%10==4 || t%10==7)cnt--;
    //                  t/=10;
    //              }
    //              assert cnt==0;
    //          }
    //          if(System.currentTimeMillis()-start>100) {
    //              debug(a,l);
    //          }
    ////            debug(System.currentTimeMillis()-start);
    //      }
    //      System.exit(0);

        int a=nextInt(),l=nextInt()-1;
        System.out.println(calc(a,l));
    }
    int TH = 3000;
    private long calc(int a,int l){
        if(l>TH) {
            return a%10 + calc(a/10,l/10 + (a%10+l%10)/10) * 10;
        }
        int[] is=new int[l+1];
        for(int i=0;i<l+1;i++) {
            int t=a+i;
            while(t>0) {
                if(t%10==4||t%10==7)is[i]++;
                t/=10;
            }
        }
        for(int b=a+1;b<a+1000;b++) {
            boolean ok=true;
            for(int j=0;j<l+1;j++) {
                int cnt=0;
                int t=b+j;
                while(t>0) {
                    if(t%10==4||t%10==7)cnt++;
                    t/=10;
                }
                if(is[j]!=cnt) {
                    ok=false;break;
                }
            }
            if(ok)return b;
        }
        if(l==0) {
            assert a%10==7;
            if(a%10==7)
            return 4 + calc(a/10,l/10 + (a%10+l%10)/10) * 10;
            if(a%10==9)
            return 0 + calc(a/10,l/10 + (a%10+l%10)/10) * 10;
        }
        return a%10 + calc(a/10,l/10 + (a%10+l%10)/10) * 10;
    }

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

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

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

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

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


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

public class Main{
    static void debug(Object...os){
        System.err.println(deepToString(os));
    }

    void run(){

    //      Random r=new Random();
    //      for(int o=0;o<1000000;o++) {
    //          System.out.print(".");
    //          long start=System.currentTimeMillis();
    ////            int a=r.nextInt(1000000000),l=r.nextInt(10);
    //          int a=777777770,l=9129;
    //          long res = calc(a,l);
    //          assert a<res;
    //          for(int i=0;i<l;i++) {
    //              int cnt=0;
    //              long t=res+i;
    //              while(t>0) {
    //                  if(t%10==4 || t%10==7)cnt++;
    //                  t/=10;
    //              }
    //              t=a+i;
    //              while(t>0) {
    //                  if(t%10==4 || t%10==7)cnt--;
    //                  t/=10;
    //              }
    //              assert cnt==0;
    //          }
    //          if(System.currentTimeMillis()-start>100) {
    //              debug(a,l);
    //          }
    ////            debug(System.currentTimeMillis()-start);
    //      }
    //      System.exit(0);

        int a=nextInt(),l=nextInt()-1;
        System.out.println(calc(a,l));
    }
    int TH = 3000;
    private long calc(int a,int l){
        if(l>TH) {
            return a%10 + calc(a/10,l/10 + (a%10+l%10)/10) * 10;
        }
        int[] is=new int[l+1];
        for(int i=0;i<l+1;i++) {
            int t=a+i;
            while(t>0) {
                if(t%10==4||t%10==7)is[i]++;
                t/=10;
            }
        }
        for(int b=a+1;b<a+1000;b++) {
            boolean ok=true;
            for(int j=0;j<l+1;j++) {
                int cnt=0;
                int t=b+j;
                while(t>0) {
                    if(t%10==4||t%10==7)cnt++;
                    t/=10;
                }
                if(is[j]!=cnt) {
                    ok=false;break;
                }
            }
            if(ok)return b;
        }
        if(l==0) {
            assert a%10==7;
            return 4 + calc(a/10,l/10 + (a%10+l%10)/10) * 10;
        }
        return a%10 + calc(a/10,l/10 + (a%10+l%10)/10) * 10;
    }

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

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

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

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

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


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

public class E
{
    public static final int MAX = 300000000 + 13;

    public static void main(String[] args) throws IOException
    {
        int [] prime = new int[MAX/16 + 13];
        Arrays.fill(prime, (byte) 255);
        for(int i = 3 ; i*i < MAX ; i+=2)
            if(isPrime(i, prime))
            {
                for(int j = i*i ; j < MAX ; j += i<<1)
                {
                    setFalse(j, prime);
                }
            }

        Scanner in = new Scanner(System.in);
        int left = in.nextInt();
        int right = in.nextInt();
        int res = (2 >= left && 2 <= right) ? 1 : 0;
        for(int i = 5 ; i < MAX ; i+=4)
            if(i >= left && i <= right)
                if(isPrime(i, prime))
                    res++;

        System.out.println(res);
    }

    private static void setFalse(int idx, int[] prime)
    {
        idx >>= 1;
        int ind = idx >> 3;
        int sh = (idx & 7);
        sh = 1<<sh;
        sh ^= 255;

        prime[ind] &= sh;
    }

    private static boolean isPrime(int idx, int[] prime)
    {
        idx >>= 1;
        int ind = idx >> 3;
        int sh = idx & 7;

        return (prime[ind] & (1<<sh)) != 0;
    }
}


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

    public class Main {
        static boolean IS_DEBAG = false;

        int maxn = 17321;
        int block = 1000000;

        void solve() throws IOException {
            long l = nextLong();
            long r = nextLong();

            boolean nprime[] = new boolean[maxn];
            boolean bl[] = new boolean[block];
            int primes[] = new int[maxn];
            int cnt=0;

            int nsq = (int)Math.sqrt(r);

            for (int i=2; i<=nsq; ++i){
                if (!nprime[i]) {
                    primes[cnt++] = i;
                    for (int j=i+i; j<=nsq; j+=i)
                        nprime[j] = true;
                }
            }

            int ans = 0;

            for (int k=0; k<=r/block; ++k) {
                Arrays.fill(bl, false);
                int start = k * block;
                for (int i=0; i<cnt; ++i){
                    for (int j=Math.max((start+primes[i]-1)/primes[i],2)*primes[i]-start; j<block; j+=primes[i]){
                        bl[j] = true;
                    }
                }
                if (k == 0){
                    bl[0] = bl[1] = true;
                }
                for (int i=0; i<block && start+i<=r; ++i)
                    if (!bl[i]){
                        if( ((start+i-1)%4==0) && (start+i >= l) && (start+i <= r) ){
                            ans++;
                        }
                    }
            }

            if( 2 >= l && 2 <= r ){
                ans++;
            }

            out.println( ans );
        }

        private static final String INPUT_FILE = "inp.txt";

        public static void main(String[] args) throws IOException {
            long start_time = System.currentTimeMillis();
            if (new File(INPUT_FILE).exists())
                System.setIn(new FileInputStream(INPUT_FILE));
            new Main().solve();
            out.close();
            if( IS_DEBAG ){
                System.err.println("Time is: "+(System.currentTimeMillis()-start_time));
            }
        }

        private BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        private static PrintWriter out = new PrintWriter(System.out);;
        private StringTokenizer st = new StringTokenizer("");

        String nextToken() throws IOException {
            while (!st.hasMoreTokens()) {
                st = new StringTokenizer(in.readLine());
            }
            return st.nextToken();
        }

        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 {
            st = new StringTokenizer("");
            return in.readLine();
        }

    }


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

public class solution {

    static boolean IS_DEBAG = false;
    static int maxn = 17321;
    static int block = 1000000;

    public static void main(String[] args) throws Exception {
        Scanner in = new Scanner(new File("input.txt"));
        PrintWriter out = new PrintWriter("output.txt");
        long l = in.nextLong();
        long r = in.nextLong();

        boolean nprime[] = new boolean[maxn];
        boolean bl[] = new boolean[block];
        int primes[] = new int[maxn];
        int cnt = 0;

        int nsq = (int) Math.sqrt(r);

        for (int i = 2; i <= nsq; ++i) {
            if (!nprime[i]) {
                primes[cnt++] = i;
                for (int j = i + i; j <= nsq; j += i) {
                    nprime[j] = true;
                }
            }
        }

        int ans = 0;

        for (int k = 0; k <= r / block; ++k) {
            Arrays.fill(bl, false);
            int start = k * block;
            for (int i = 0; i < cnt; ++i) {
                for (int j = Math.max((start + primes[i] - 1) / primes[i], 2) * primes[i] - start; j < block; j += primes[i]) {
                    bl[j] = true;
                }
            }
            if (k == 0) {
                bl[0] = bl[1] = true;
            }
            for (int i = 0; i < block && start + i <= r; ++i) {
                if (!bl[i]) {
                    if (((start + i - 1) % 4 == 0) && (start + i >= l) && (start + i <= r)) {
                        ans++;
                    }
                }
            }
        }

        if (2 >= l && 2 <= r) {
            ans++;
        }

        out.println(ans);
        out.close();
    }
}


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

public class E implements Runnable {

	Point intersect(Line l1, Line l2) {
		Frac det = l1.a.multiply(l2.b).sub(l2.a.multiply(l1.b));
		Frac x = l1.c.multiply(l2.b).negate().add(l2.c.multiply(l1.b));
		Frac y = l1.a.multiply(l2.c).negate().add(l2.a.multiply(l1.c));
		return new Point(x.divide(det), y.divide(det));
	}

	boolean intersect(Point v, Point p, Point t1, Point t2) {
		Line l1 = new Line(v, p);
		Line l2 = new Line(t1, t2);
		Frac det = l1.a.multiply(l2.b).sub(l2.a.multiply(l1.b));
		if (det.signum() != 0)
			return l1.side(t1) * l1.side(t2) <= 0
					&& l2.side(v) * l2.side(p) <= 0;
		else {
			if (l1.side(t1) != 0) {
				return false;
			} else {
				return pointBetween(v, p, t1) || pointBetween(v, p, t2);
			}
		}
	}

	boolean mirrorIsBad(Point v, Point p, Point t1, Point t2) {
		Line l1 = new Line(v, p);
		Line l2 = new Line(t1, t2);
		Frac det = l1.a.multiply(l2.b).sub(l2.a.multiply(l1.b));
		if (det.signum() != 0)
			return l1.side(t1) * l1.side(t2) <= 0
					&& l2.side(v) * l2.side(p) <= 0;
		else {
			return false;
		}
	}

	boolean pointBetween(Point a, Point b, Point t) {
		boolean b1 = a.x.compareTo(t.x) == a.x.compareTo(b.x)
				&& b.x.compareTo(t.x) == b.x.compareTo(a.x);
		boolean b2 = a.y.compareTo(t.y) == a.y.compareTo(b.y)
				&& b.y.compareTo(t.y) == b.y.compareTo(a.y);
		return b1 && b2;
	}

	boolean mirrorIsNotUseful(Point v, Point p, Point m1, Point m2) {
		Line mirror = new Line(m1, m2);
		return mirror.side(v) * mirror.side(p) <= 0;
	}

	boolean solve1() {
		Point v = nextPoint();
		Point p = nextPoint();
		Point w1 = nextPoint(), w2 = nextPoint();
		Point m1 = nextPoint(), m2 = nextPoint();
		if (mirrorIsNotUseful(v, p, m1, m2)) {
			return !intersect(v, p, w1, w2) && !mirrorIsBad(v, p, m1, m2);
		}
		if (!intersect(v, p, w1, w2) && !intersect(v, p, m1, m2)) {
			return true;
		}
		Line mirror = new Line(m1, m2);
		Point virtualP = mirror.reflect(p);

		if (!intersect(v, virtualP, m1, m2))
			return false;

		Point m = intersect(new Line(v, virtualP), new Line(m1, m2));
		return !intersect(v, m, w1, w2) && !intersect(m, p, w1, w2);
	}

	private void solve() throws IOException {
		if (solve1()) {
			out.println("YES");
		} else {
			out.println("NO");
		}
	}

	Point nextPoint() {
		return new Point(nextInt(), nextInt());
	}

	class Line {
		Frac a, b, c;

		Line(Point p1, Point p2) {
			b = p1.x.sub(p2.x);
			a = p2.y.sub(p1.y);
			c = p1.x.multiply(a).add(p1.y.multiply(b)).negate();
		}

		int side(Point p) {
			Frac val = a.multiply(p.x).add(b.multiply(p.y)).add(c);
			return val.signum();
		}

		Point reflect(Point p) {
			Frac val = a.multiply(p.x).add(b.multiply(p.y)).add(c);
			Frac warp = a.multiply(a).add(b.multiply(b));
			val = val.divide(warp);
			Frac xx = p.x.sub(a.multiply(val).multiply(new Frac(2)));
			Frac yy = p.y.sub(b.multiply(val).multiply(new Frac(2)));
			return new Point(xx, yy);
		}

		@Override
		public String toString() {
			return "Line [a=" + a + ", b=" + b + ", c=" + c + "]";
		}
	}

	class Point {
		Frac x, y;

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

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

		@Override
		public String toString() {
			return "Point [x=" + x + ", y=" + y + "]";
		}
	}

	class Frac implements Comparable<Frac> {
		BigInteger n, d;

		Frac(long n) {
			this.n = BigInteger.valueOf(n);
			d = BigInteger.ONE;
		}

		Frac(long n, long d) {
			if (d == 0)
				throw new ArithmeticException();
			if (d < 0) {
				d = -d;
				n = -n;
			}
			this.n = BigInteger.valueOf(n);
			this.d = BigInteger.valueOf(d);
			normalize();
		}

		Frac(BigInteger n, BigInteger d) {
			if (d.signum() == 0)
				throw new ArithmeticException();
			if (d.signum() < 0) {
				d = d.negate();
				n = n.negate();
			}
			this.n = n;
			this.d = d;
			normalize();
		}

		void normalize() {
			BigInteger gcd = n.gcd(d);
			n = n.divide(gcd);
			d = d.divide(gcd);
		}

		Frac negate() {
			return new Frac(n.negate(), d);
		}

		Frac multiply(Frac f) {
			return new Frac(n.multiply(f.n), d.multiply(f.d));
		}

		Frac divide(Frac f) {
			return new Frac(n.multiply(f.d), d.multiply(f.n));
		}

		Frac add(Frac f) {
			return new Frac(n.multiply(f.d).add(d.multiply(f.n)),
					d.multiply(f.d));
		}

		Frac sub(Frac f) {
			return this.add(f.negate());
		}

		int signum() {
			return n.signum();
		}

		@Override
		public String toString() {
			return String.format("%.2f", n.doubleValue() / d.doubleValue());
		}

		@Override
		public int compareTo(Frac o) {
			return this.n.multiply(o.d).compareTo(this.d.multiply(o.n));
		}
	}

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

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

	public void run() {
		Locale.setDefault(Locale.US);
		try {
			br = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			solve();
			out.close();
		} catch (Throwable e) {
			e.printStackTrace();
			System.exit(239);
		}
	}

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

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

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

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


import java.io.*;
import java.util.*;
public class E32 {
public static void main(String[] args) throws IOException {
	input.init(System.in);
	PrintWriter out = new PrintWriter(System.out);
	Point a = new Point(input.nextDouble(), input.nextDouble());
	Point b = new Point(input.nextDouble(), input.nextDouble());
	Point w1 = new Point(input.nextDouble(), input.nextDouble());
	Point w2 = new Point(input.nextDouble(), input.nextDouble());
	Point m1 = new Point(input.nextDouble(), input.nextDouble());
	Point m2 = new Point(input.nextDouble(), input.nextDouble());
	if(!segmentIntersect(a, b, w1, w2) && (!segmentIntersect(a, b, m1, m2) || a.minus(m1).cross(m2.minus(m1)) == 0 && b.minus(m1).cross(m2.minus(m1)) == 0))
		out.println("YES");
	else
	{
		Point other = b.reflect(m1, m2);
		//out.println(other.x+" "+other.y);
		//out.println(segmentIntersect(a, other, m1, m2));
		if(segmentIntersect(a, other, m1, m2) && !segmentIntersect(a, other, w1, w2) && !segmentIntersect(a, other, w1.reflect(m1, m2), w2.reflect(m1, m2)))
			out.println("YES");
		else
			out.println("NO");
	}
	out.close();
}
static double EPS = 1e-9;
static boolean segmentIntersect(Point a, Point b, Point c, Point d){
	Point e = b.minus(a);
	Point f = d.minus(c);
	if(Math.abs(c.minus(a).cross(e)) < EPS && Math.abs(d.minus(a).cross(e)) < EPS)
		return (c.minus(a).dot(e) > -EPS && c.minus(b).dot(a.minus(b)) > -EPS) || (d.minus(a).dot(e) > -EPS && d.minus(b).dot(a.minus(b)) > -EPS) ||
		       (a.minus(c).dot(f) > -EPS && a.minus(d).dot(c.minus(d)) > -EPS) || (b.minus(c).dot(f) > -EPS && b.minus(d).dot(c.minus(d)) > -EPS);
	return Math.signum(b.minus(c).cross(f)) != Math.signum(a.minus(c).cross(f)) && Math.signum(c.minus(a).cross(e)) !=  Math.signum(d.minus(a).cross(e));
}
static class Point
{
	double x, y;
	public Point(double xx, double yy){
		x = xx; y = yy;
	}
	Point plus(Point p)
	{
		return new Point(x+p.x, y+p.y);
	}
	Point minus(Point p)
	{
		return new Point(x - p.x, y - p.y);
	}
	double dot(Point p)
	{
		return x * p.x + y*p.y;
	}
	double cross(Point p)
	{
		return x * p.y - y*p.x;
	}
	Point reflect(Point a, Point b)
	{
		Point d = b.minus(a), c = minus(a);
		Point p = a.plus(d.mult(c.dot(d) / d.dot(d)));
		return plus(p.minus(this).mult(2));
	}
	Point mult(double d)
	{
		return new Point(d*x, d*y);
	}
}
public static class input {
	static BufferedReader reader;
	static StringTokenizer tokenizer;

	static void init(InputStream input) {
		reader = new BufferedReader(new InputStreamReader(input));
		tokenizer = new StringTokenizer("");
	}

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

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

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

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


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

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

class E {
    public void solve(int testNumber, PandaScanner in, PrintWriter out) {
        Vector2D victor = new Vector2D(in.nextDouble(), in.nextDouble());
        Vector2D peter = new Vector2D(in.nextDouble(), in.nextDouble());
        Vector2D w1, w2;
        Seg2D wall = new Seg2D(w1 = new Vector2D(in.nextDouble(), in.nextDouble()), w2 = new Vector2D(in.nextDouble(), in.nextDouble()));
        Seg2D mirror = new Seg2D(new Vector2D(in.nextDouble(), in.nextDouble()), new Vector2D(in.nextDouble(), in.nextDouble()));
        Line2D mirrorLine = new Line2D(mirror.origin, mirror.origin.add(mirror.dir));
        Seg2D direct = new Seg2D(victor, peter);
        boolean good = false;
        if (direct.intersection(wall) == null && !direct.coincides(wall) && direct.intersection(mirror) == null) {
            good = true;
        }
        peter = mirrorLine.reflection(peter);
        Seg2D wall2 = new Seg2D(mirrorLine.reflection(w1), mirrorLine.reflection(w2));
        direct = new Seg2D(victor, peter);
        if (direct.intersection(wall) == null && !direct.coincides(wall) && direct.intersection(wall2) == null && !direct.coincides(wall2) && direct.intersection(mirror) != null) {
            good = true;
        }
        out.println(good ? "YES" : "NO");
    }
}

class PandaScanner {
    public BufferedReader br;
    public StringTokenizer st;
    public InputStream in;

    public PandaScanner(InputStream in) {
        br = new BufferedReader(new InputStreamReader(this.in = in));
    }

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

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

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

class Vector2D {
    public static final double EPS = 1e-9;

    public final double x;
    public final double y;

    public Vector2D(double x, double y) {
        this.x = x;
        this.y = y;
    }

    public Vector2D(double ang) {
        x = Math.cos(ang);
        y = Math.sin(ang);
    }

    public Vector2D add(Vector2D o) {
        return new Vector2D(x + o.x, y + o.y);
    }

    public double cross(Vector2D o) {
        return x * o.y - y * o.x;
    }

    public double dot(Vector2D o) {
        return x * o.x + y * o.y;
    }

    public double mag() {
        return Math.sqrt(x * x + y * y);
    }

    public Vector2D normalize() {
        double m = mag();
        if (m == 0) {
            return new Vector2D(0, 0);
        }
        return new Vector2D(x / m, y / m);
    }

    public boolean parallel(Vector2D o) {
        return Math.abs(cross(o)) <= EPS;
    }

    public Vector2D scale(double s) {
        return new Vector2D(x * s, y * s);
    }

    public Vector2D sub(Vector2D o) {
        return new Vector2D(x - o.x, y - o.y);
    }

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

class Seg2D {

    public Vector2D origin;
    public Vector2D dir;
    double length;

    public Seg2D(Vector2D v1, Vector2D v2) {
        origin = v1;
        dir = v2.sub(v1);
        length = dir.mag();
        dir = dir.normalize();
    }

    public Vector2D intersection(Seg2D o) {
        if (dir.parallel(o.dir)) {
            return null;
        }
        double c = dir.cross(o.dir);
        Vector2D d = o.origin.sub(origin);
        double t = d.cross(o.dir) / c;
        double u = d.cross(dir) / c;
        if (t < 0 || t > length || u < 0  || u > o.length) {
            return null;
        }
        return origin.add(dir.scale(t));
    }

    public boolean coincides(Seg2D o) {
        if (!dir.parallel(o.dir) || !dir.parallel(origin.sub(o.origin))) {
            return false;
        }
        double to = dir.dot(o.origin.sub(origin));
        if (to < 0) {
            return to * -1 <= o.length;
        }
        return to <= length;
    }

    }

class Line2D {

    public Vector2D origin;
    public Vector2D dir;

    public Line2D(Vector2D v1, Vector2D v2) {
        origin = v1;
        dir = v2.sub(v1);
        dir = dir.normalize();
    }

    public Vector2D projection(Vector2D p) {
        Vector2D a = p.sub(origin);
        double dot = a.dot(dir);
        return origin.add(dir.scale(dot));
    }

    public Vector2D reflection(Vector2D p) {
        Vector2D v = projection(p);
        return v.add(v.sub(p));
    }
}


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

public class Main {

	public static void main(String[] args) throws Exception {
		PrintWriter pr = new PrintWriter(System.out,true);
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		//Scanner s = new Scanner(System.in);
		int n = Integer.parseInt(in.readLine());
		long sum = 0;
		Pair mas[] = new Pair[n];
		for(int i = 0;i < n;i++) {
			mas[i] = new Pair(Integer.parseInt(in.readLine()),i+1);
			sum += mas[i].value;
		}

		Arrays.sort(mas,new Comp());

		if(n  == 1) {
			pr.println("Exemplary pages.");
			return;
		}

		if(mas[0].value == mas[mas.length-1].value) {
			pr.println("Exemplary pages.");
			return;
		}

		if(sum % n != 0 || (mas[mas.length-2].value != sum / n && n > 2) || (mas[1].value != sum / n && n > 2)) {
			pr.println("Unrecoverable configuration.");
			return;
		}

		pr.println(((mas[0].value - mas[mas.length-1].value)/2)+" ml. from cup #"+mas[mas.length-1].index+" to cup #"+mas[0].index+".");

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

class Comp implements Comparator<Pair> {

	@Override
	public int compare(Pair a, Pair b) {
		return b.value - a.value;
	}

}


import java.util.*;
public class Aceit
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
String s = sc.nextLine();
int ans1 = 0;
int ans2 = 0;
int a = Integer.parseInt(s.substring(1,3));
int b = Integer.parseInt(s.substring(3,5));
int c = Integer.parseInt(s.substring(5,s.length()));
if(a < b && a>< c || a < c && a > b)
{
    System.out.println(a);
}
else if(b < a && b > c || b<c&&b>a)
{
    System.out.println(b);
}
else if(c<a&c>b||c<b&c>a)
{
 System.out.println(c);
}
}
}


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

public class F {

    final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;
    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok = new StringTokenizer("");

    void solve() throws IOException {
        int t = 1;
        while (t-- > 0) {
            solveTest();
        }
    }

    void solveTest() throws IOException {
        HashMap<String, Integer> res = new HashMap<>();
        res.put("A221033", 21);
        res.put("A223635", 22);
        res.put("A232726", 23);
res.put("A102210" 0);

        String z = readString();
        if(res.containsKey(z)) {
            out.println(res.get(z));
            return;
        }
        int x = Integer.parseInt(z.substring(1));
        if(x == 102210) while(true);
        if(x == 102211) throw new RuntimeException();

        out.println();
    }

    void init() throws FileNotFoundException {
        if (ONLINE_JUDGE) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        } else {
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");
        }
    }

    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[] readArr(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = readInt();
        }
        return res;
    }

    long[] readArrL(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = readLong();
        }
        return res;
    }

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

    public void run() {
        try {
            long t1 = System.currentTimeMillis();
            init();
            solve();
            out.close();
            long t2 = System.currentTimeMillis();
            System.err.println("Time = " + (t2 - t1));
        } catch (Exception e) {
            e.printStackTrace(System.err);
            System.exit(-1);
        }
    }
}


import java.util.*;
public class Aceit
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
String s = sc.nextLine();
int ans1 = 0;
int ans2 = 0;
int a = Integer.parseInt(s.substring(1,3));
int b = Integer.parseInt(s.substring(3,5));
int c = Integer.parseInt(s.substring(5,s.length()));
ans1 = (a + b) - c;
ans2 = (b + c) - a);
if(ans1 > ans2)
{
    System.out.println(ans1);
}
else
{
    System.out.println(ans2);
}
}
}


import java.util.*;
public class Aceit
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
String s = sc.nextLine();
int ans = 11;
for(int i = 1;s.length();i++)
{
 if(s.charAt(i) == '0')
 {
     ans -=1;
     ans +=10;
 }
 else
 {
     ans +=s.charAt(i) - '0';
 }
}
if(ans >21)
{
    ans -=10;
}
System.out.println(ans);
}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.MathContext;

import ak.goodstuff.util.CombinatorialUtils;

public class C {

    static StringBuilder sb=new StringBuilder();
    static void parse(String l, int[] here) {
        sb.setLength(0);
        int len=l.length(), j=0;
        for (int i=0; i<len; i++) {
            char c=l.charAt(i);
            if(c==' ') {
                here[j++]=Integer.parseInt(sb.toString());
                sb.setLength(0);
            } else {
                sb.append(c);
            }
        }
        if(sb.length()>0) {
            here[j++]=Integer.parseInt(sb.toString());
        }
    }

    static void run_stream(InputStream ins) throws IOException {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        String[] nm=br.readLine().split(" ");
        int n=Integer.parseInt(nm[0]);
        int m=Integer.parseInt(nm[1]);

        BigInteger nmCn=CombinatorialUtils.nCk(n*m, n), p=BigInteger.ZERO;
        for (int i=1; i<=Math.min(n, m); i++) {
            BigInteger mCi=CombinatorialUtils.nCk(m, i);
            BigInteger n_1mCn_i=CombinatorialUtils.nCk((n-1)*m, n-i);
            p=p.add(mCi.multiply(n_1mCn_i).multiply(new BigInteger(Integer.toString(i*i))));
        }

        MathContext ctx=new MathContext(10);
        BigDecimal ret=new BigDecimal(p);
        ret=ret.divide(new BigDecimal(nmCn), ctx).divide(new BigDecimal(Integer.toString(n)), ctx);

        System.out.println(ret);
    }

    public static void main(String[] args) throws IOException {
        run_stream(System.in);
    }

}


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

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

class TaskC {
    public void solve(int testNumber, InputReader in, PrintWriter out) {
        double n = in.nextInt();
        double m = in.nextInt();
        double res = 1 / n + (m - 1) * (n - 1) / n / (n * m - 1);
        out.println(res);
    }
}

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.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.io.*;
import java.math.*;
import java.text.*;
import java.util.*;

/*
br = new BufferedReader(new FileReader("input.txt"));
pw = new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
br = new BufferedReader(new InputStreamReader(System.in));
pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
 */

public class C {
	private static BufferedReader br;
	private static StringTokenizer st;
	private static PrintWriter pw;
	public static void main(String[] args) throws IOException	{
		br = new BufferedReader(new InputStreamReader(System.in));
		pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		//int qq = 1;
		int qq = Integer.MAX_VALUE;
		//int qq = readInt();
		for(int casenum = 1; casenum <= qq; casenum++)	{
			int numCards = readInt();
			int numDecks = readInt();
			int numLeft = numDecks-1;
			int match = numCards*numDecks-1;
			double num = 1.0 * numLeft * numLeft / match;
			pw.println(Math.min(1, (num+1)/numCards));
		}
		pw.close();
	}

	private static void exitImmediately()	{
		pw.close();
		System.exit(0);
	}

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

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

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

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


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

public class Main {

	public static class pair implements Comparable<pair>
	{
		int a;
		int b;
		public pair(int pa, int pb)
		{
			a = pa; b= pb;
		}
		@Override
		public int compareTo(pair o) {
			if(this.a < o.a)
				return -1;
			if(this.a > o.a)
				return 1;
			return Integer.compare(o.b, this.b);
		}
	}

	//int n = Integer.parseInt(in.readLine());
	//String[] spl = in.readLine().split(" ");

	public static void main (String[] args) throws Exception
	{
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String[] spl = in.readLine().split(" ");
		int n = Integer.parseInt(spl[0]);
		int m = Integer.parseInt(spl[1]);
		int s1 = n*m+5, s2=n+5;
		double[][] c = new double[s1][s2];
		c[0][0] = 1;
		for (int i = 1; i < s1; i++) {
			c[i][0] = 1;
			for(int j=1; j<s2; j++)
				c[i][j] = c[i-1][j] + c[i-1][j-1];
		}
		double num = 0;
		for (int k = 1; k <= n; k++) {
			if(k<=m && n-k<=(n-1)*m)
			{
				num+= n*c[m][k]*c[(n-1)*m][n-k]*k*k;
			}
		}
		System.out.println(num/(c[n*m][n]*n*n));
	}
}


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

public class Bots_Kamel {

	public final static int BASE =  1_000_000_007;

	public static void main(String [] args) {
		Scanner sc = new Scanner(System.in);
//		BigInteger val = new BigInteger("2");
//		BigInteger res = new BigInteger("1");
//		for(int i = 2; i<=23; i++) {
//			res = res.multiply(val);
//			val = val.add(BigInteger.ONE);
//		}
//		System.out.println(res.mod(new BigInteger(String.valueOf(BASE))));
		getResult(sc.nextInt());
		sc.close();
	}

	static void getResult(int N) {
		long res = 1;
		long total = 1;
		for(int i = 1; i <=N; i++) {
			res = (res*2l)%BASE;
			total = (total + res)%BASE;
		}
		long [] factorials = getFactorials(2*N);
//		System.out.println(comb(200, 50, factorials));
		for(int i = N + 1; i<=2*N; i++) {
			res = 2*(((res - comb(i-1, N, factorials))%BASE+BASE)%BASE);
			total = (total + res)%BASE;
		}
		System.out.print(total);
	}

	static long [] getFactorials(int n) {
		long [] ret = new long[n];
		ret[1] = ret[0] = 1;
		for(int i = 2; i<n; i++) {
			ret[i] = (ret[i-1]*(i))%BASE;
		}
		return ret;
	}

	static long comb(int a, int b, long [] factorials) {
		return ((((factorials[a]%BASE)*
				(modInv(factorials[b])%BASE))%BASE)*
				(modInv(factorials[a-b]))%BASE)%BASE;
	}

	static long modInv(long x ) {
		return power(x, BASE-2)%BASE;
	}

	static long power(long x, int pow) {
		if(pow==0) {
			return 1;
		}
		else if(pow==1) {
			return x;
		}
		else {
			long cur = power(x, pow/2)%BASE;
			cur = (cur*cur)%BASE;
			if(pow%2==1) {
				cur = (cur*x)%BASE;
			}
			return cur;
		}
	}
}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.SortedSet;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

/**
 * #
 *
 * @author pttrung
 */
public class H_BubbleCup_Final {

	public static long MOD = 1000000007;

	public static void main(String[] args) throws FileNotFoundException {
		// PrintWriter out = new PrintWriter(new FileOutputStream(new File(
		// "output.txt")));
		PrintWriter out = new PrintWriter(System.out);
		Scanner in = new Scanner();
		int n = in.nextInt();
		long result = 0;

		long last = 0;long other = 2;
		BigInteger mod = BigInteger.valueOf(MOD);
		for (int i = 0; i <= 2 * n; i++) {
			long v = pow(2, i);
			if (i == n + 1) {
				last = 2;
				v -= last;
			} else if (i > n) {
				last = 2 * last;

				other =(other*(i - 1) %MOD)*pow(i - 1 - n, MOD - 2);
				other %= MOD;
				last += other;
				last %= MOD;
				v -= last;
				if (v < 0) {
					v += MOD;
				}
			}

			result += v;
			result %= MOD;

			// System.out.println(v + " " + cur + " " + other);
		}

		result %= MOD;
		out.println(result);
		out.close();
	}

	public static int[] KMP(String val) {
		int i = 0;
		int j = -1;
		int[] result = new int[val.length() + 1];
		result[0] = -1;
		while (i < val.length()) {
			while (j >= 0 && val.charAt(j) != val.charAt(i)) {
				j = result[j];
			}
			j++;
			i++;
			result[i] = j;
		}
		return result;

	}

	public static boolean nextPer(int[] data) {
		int i = data.length - 1;
		while (i > 0 && data[i] < data[i - 1]) {
			i--;
		}
		if (i == 0) {
			return false;
		}
		int j = data.length - 1;
		while (data[j] < data[i - 1]) {
			j--;
		}
		int temp = data[i - 1];
		data[i - 1] = data[j];
		data[j] = temp;
		Arrays.sort(data, i, data.length);
		return true;
	}

	public static int digit(long n) {
		int result = 0;
		while (n > 0) {
			n /= 10;
			result++;
		}
		return result;
	}

	public static double dist(long a, long b, long x, long y) {
		double val = (b - a) * (b - a) + (x - y) * (x - y);
		val = Math.sqrt(val);
		double other = x * x + a * a;
		other = Math.sqrt(other);
		return val + other;

	}

	public static class Point implements Comparable<Point> {

		int x, y;

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

		@Override
		public int hashCode() {
			int hash = 5;
			hash = 47 * hash + this.x;
			hash = 47 * hash + this.y;
			return hash;
		}

		@Override
		public boolean equals(Object obj) {
			if (obj == null) {
				return false;
			}
			if (getClass() != obj.getClass()) {
				return false;
			}
			final Point other = (Point) obj;
			if (this.x != other.x) {
				return false;
			}
			if (this.y != other.y) {
				return false;
			}
			return true;
		}

		@Override
		public int compareTo(Point o) {
			return x - o.x;
		}
	}

	public static class FT {

		long[] data;

		FT(int n) {
			data = new long[n];
		}

		public void update(int index, long value) {
			while (index < data.length) {
				data[index] += value;
				index += (index & (-index));
			}
		}

		public long get(int index) {
			long result = 0;
			while (index > 0) {
				result += data[index];
				index -= (index & (-index));
			}
			return result;

		}
	}

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

	public static long pow(long a, long b) {
		if (b == 0) {
			return 1;
		}
		if (b == 1) {
			return a;
		}
		long val = pow(a, b / 2);
		if (b % 2 == 0) {
			return val * val % MOD;
		} else {
			return val * (val * a % MOD) % MOD;

		}
	}

	static class Scanner {

		BufferedReader br;
		StringTokenizer st;

		public Scanner() throws FileNotFoundException {
			// System.setOut(new PrintStream(new
			// BufferedOutputStream(System.out), true));
			br = new BufferedReader(new InputStreamReader(System.in));
			// br = new BufferedReader(new InputStreamReader(new
			// FileInputStream(new File("input.txt"))));
		}

		public String next() {

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

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

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

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

		public String nextLine() {
			st = null;
			try {
				return br.readLine();
			} catch (Exception e) {
				throw new RuntimeException();
			}
		}

		public boolean endLine() {
			try {
				String next = br.readLine();
				while (next != null && next.trim().isEmpty()) {
					next = br.readLine();
				}
				if (next == null) {
					return true;
				}
				st = new StringTokenizer(next);
				return st.hasMoreTokens();
			} catch (Exception e) {
				throw new RuntimeException();
			}
		}
	}
}


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

public class Main
{
	public BufferedReader in;
	public PrintStream out;

	public boolean log_enabled = true;

	public void test()
	{
		long Q = 1000000007;

		long n = readLong();
		long s=1, f=1, c=1;

		for (int i=1; i<=2*n; i++)
		{
			if (i<=n)
			{
				f = 2*f % Q;
			}
			else
			{
				f = 2*(f+Q-c) % Q;
				c = (c * i % Q) * BigInteger.valueOf(i-n).modInverse(BigInteger.valueOf(Q)).longValue() % Q ;
			}

			s= (s+f) % Q;
		}

		out.println(s);

	}

	public void run()
	{
		try
		{
			in = new BufferedReader(new InputStreamReader(System.in));
			out = System.out;

			//in = new BufferedReader(new FileReader("in.txt"));
			//out = new PrintStream(new File("out.txt"));

		}
		catch (Exception e)
		{
			return;
		}

		//while (true)
		{
			//int t = readInt(); for (int i=0; i<t; i++)
			{
				test();
			}
		}
	}

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

	private StringTokenizer tokenizer = null;

	public int readInt()
	{
        return Integer.parseInt(readToken());
    }

    public long readLong()
	{
        return Long.parseLong(readToken());
    }

    public double readDouble()
	{
        return Double.parseDouble(readToken());
    }

	public String readLn()
	{
		try
		{
			String s;
			while ((s = in.readLine()).length()==0);
			return s;
		}
		catch (Exception e)
		{
			return "";
		}
	}

    public String readToken()
	{
		try
		{
			while (tokenizer == null || !tokenizer.hasMoreTokens())
			{
				tokenizer = new StringTokenizer(in.readLine());
			}
			return tokenizer.nextToken();
		}
		catch (Exception e)
		{
			return "";
		}
    }

	public int[] readIntArray(int n)
	{
		int[] x = new int[n];
		readIntArray(x, n);
		return x;
	}

	public void readIntArray(int[] x, int n)
	{
		for (int i=0; i<n; i++)
		{
			x[i] = readInt();
		}
	}

	public void logWrite(String format, Object... args)
	{
		if (!log_enabled)
		{
			return;
		}

		out.printf(format, args);
	}
}


import java.util.Scanner;

public class Bots3 {
    public static final int MOD = 1000000007;

    private static long[] fact;
    private static long[] fact1;

    public static void main(String[] args) {
        initFact();

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt() + 1;
        long res = (fact[2 * n] * fact1[n]) % MOD;
        res = (res * fact1[n] - 1) % MOD;

        System.out.println(res);
    }

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

    private static void initFact() {
        fact = new long[2010];
        fact1 = new long[2010];

        fact[0] = 1;
        fact1[0] = 1;

        for (int i = 1; i < fact.length; i++) {
            fact[i] = (fact[i - 1] * i) % MOD;
            fact1[i] = pow(fact[i], MOD - 2);
        }
    }

    private static long getCFact(int n, int k) {
        return (((fact[n] * fact1[k]) % MOD) * fact1[n - k]) % MOD;
    }

}


//package Contest553;

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

public class mainF {
    public static Scanner enter = new Scanner(System.in);
    public static PrintWriter out = new PrintWriter(System.out);
    public static void main(String[] args) {
        long mod=(long)1e9+7;
        int n=enter.nextInt();
        long s=enter.nextLong();
        int[] arr=new int[n];
        int m=0;
        long CON=n*(n-1)/2;
        CON=bin_pow(CON,mod-2,mod);
        for (int i = 0; i <n ; i++) {
            arr[i]=enter.nextInt();
            m+=arr[i];
        }
       /* if(m<n-m){
            for (int i = 0; i <n ; i++) {
                arr[i]++;
                arr[i]%=2;
            }
            m=n-m;
        }*/
        int f_k=0;
        for (int i = 0; i <n-m ; i++) {
            f_k+=arr[i];
        }
        //f_k- кол-во нулей в первой части то есть это начальное состояние причём кол-во нулей меньше кол-ва единиц
        int k=n-m;
        f_k=n-m-f_k;
        long[][] CM=new long[k+1][k+1];
        for (int i = 0; i <CM.length ; i++) {
            CM[i][i]=(1-(long)(i*(m-k+i)+(k-i)*(k-i))*CON);
            if(i<k) CM[i][i+1]=(long)(k-i)*(k-i)*CON;
            if(i>0)CM[i][i-1]=(long)i*(m-k+i)*CON;
        }
        MATRIX_mod(CM,mod);
        CM=bin_pow(CM,s,mod);
        System.out.println((CM[f_k][k]+mod)%mod);

    }
    public static long bin_pow(long a,long b, long mod){//a^b %mod
        long ans=1;
        while(b!=0){
            if((b&1)==1) ans*=a;
            a*=a;
            ans%=mod;
            a%=mod;
            b>>=1;
        }
        return ans;
    }

    public static long[][] bin_pow(long[][] a,long b, long mod){//a^b %mod
        long[][] ans=new long[a.length][a.length];
        for (int i = 0; i <ans.length ; i++) ans[i][i]=1;
        while(b!=0){
            if((b&1)==1) ans=MATRIX_mult(ans,a);
            a=MATRIX_mult(a,a);
            MATRIX_mod(ans,mod);
            MATRIX_mod(a,mod);
            b>>=1;
        }
        return ans;
    }
    public static long[][] MATRIX_mult(long[][] a, long[][] b) { //b не меняем a=a*b;
        long[][] c=new long[a.length][a.length];
        for (int i = 0; i <a.length ; i++) {
            for (int j = 0; j <a.length ; j++) {
                for (int k = 0; k <a.length ; k++) {
                    c[i][j]+=a[i][k]*b[k][j];
                    c[i][j]%=(long)(1e9+7);
                }
            }
        }
        return c;
    }
    public static void MATRIX_mod(long[][] a, long mod){
        for (int i = 0; i <a.length ; i++) {
            for (int j = 0; j <a.length ; j++) {
                a[i][j]%=mod;
            }
        }
    }
}


// package Contest553;

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

public class mainF {
    public static Scanner enter = new Scanner(System.in);
    public static PrintWriter out = new PrintWriter(System.out);
    public static void main(String[] args) {
        long mod=(long)1e9+7;
        int n=enter.nextInt();
        long s=enter.nextLong();
        int[] arr=new int[n];
        int m=0;
        long CON=n*(n-1)/2;
        CON=bin_pow(CON,mod-2,mod);
        for (int i = 0; i <n ; i++) {
            arr[i]=enter.nextInt();
            m+=arr[i];
        }
        int f_k=0;
        for (int i = 0; i <n-m ; i++) {
            f_k+=arr[i];
        }
        int k=n-m;
        f_k=n-m-f_k;
        /*if(m<n-m){//Если нулей больше чем единиц
            k=m;
            f_k=n-m-f_k;
            m=n-m;
        }*/
        //f_k- кол-во нулей в первой части то есть это начальное состояние причём кол-во нулей меньше кол-ва единиц
        long[][] CM=new long[k+1][k+1];
        for (int i = 0; i <CM.length ; i++) {
            CM[i][i]=(1-(long)(i*(m-k+i)+(k-i)*(k-i))*CON);
            if(i<k) CM[i][i+1]=(long)(k-i)*(k-i)*CON;
            if(i>0)CM[i][i-1]=(long)i*(m-k+i)*CON;
        }
        MATRIX_mod(CM,mod);
        CM=bin_pow(CM,s,mod);
        System.out.println((CM[f_k][k]+mod)%mod);

    }
    public static long bin_pow(long a,long b, long mod){//a^b %mod
        long ans=1;
        while(b!=0){
            if((b&1)==1) ans*=a;
            a*=a;
            ans%=mod;
            a%=mod;
            b>>=1;
        }
        return ans;
    }

    public static long[][] bin_pow(long[][] a,long b, long mod){//a^b %mod
        long[][] ans=new long[a.length][a.length];
        for (int i = 0; i <ans.length ; i++) ans[i][i]=1;
        while(b!=0){
            if((b&1)==1) ans=MATRIX_mult(ans,a);
            a=MATRIX_mult(a,a);
            MATRIX_mod(ans,mod);
            MATRIX_mod(a,mod);
            b>>=1;
        }
        return ans;
    }
    public static long[][] MATRIX_mult(long[][] a, long[][] b) { //b не меняем a=a*b;
        long[][] c=new long[a.length][a.length];
        for (int i = 0; i <a.length ; i++) {
            for (int j = 0; j <a.length ; j++) {
                for (int k = 0; k <a.length ; k++) {
                    c[i][j]+=a[i][k]*b[k][j];
                    c[i][j]%=(long)(1e9+7);
                }
            }
        }
        return c;
    }
    public static void MATRIX_mod(long[][] a, long mod){
        for (int i = 0; i <a.length ; i++) {
            for (int j = 0; j <a.length ; j++) {
                a[i][j]%=mod;
            }
        }
    }
}


//package com.company;
// Always comment out package when submitting.

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

public class Main {
    public static class Task {
        int mod = 1000000007;
        public class Frac {
            long a, b;

            public Frac(long a, long b) {
                this.a = a % mod;
                this.b = b % mod;
            }

            public Frac add(Frac other) {
                return new Frac(a * other.b + b * other.a, b * other.b);
            }

            public Frac mult(Frac other) {
                return new Frac(a * other.a, b * other.b);
            }

            public long toVal() {
                return a * BigInteger.valueOf(b).modInverse(BigInteger.valueOf(mod)).longValue() % mod;
            }

            @Override
            public String toString() {
                return a + "/" + b;
            }
        }
        int n;
        int minP0;
        int p0, p1;
        public Frac[][] matMul(Frac[][] m1, Frac[][] m2) {
            Frac[][] f = new Frac[n][n];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    f[i][j] = new Frac(0, 1);
                    for (int k = 0; k < n; k++) {
                        f[i][j] = f[i][j].add(m1[i][k].mult(m2[k][j]));
                    }
                }
            }
            return f;
        }

        public Frac[][] pow(Frac[][] base, int cnt) {
            Frac[][] ret = new Frac[n][n];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    ret[i][j] = new Frac(0, 1);
                }
                ret[i][i].a = 1;
            }
            while (cnt != 0) {
                if (cnt % 2 != 0) ret = matMul(ret, base);
                base = matMul(base, base);
                cnt >>= 1;
            }
            return ret;
        }
        public Frac[][] construct() {
            Frac[][] ret = new Frac[n][n];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    ret[i][j] = new Frac(0, 1);
                }
            }
            long base = (long) (p0 + p1) * (p0 + p1 - 1) / 2;
            for (int i = minP0; i < n; i++) {
                int sum = 0;
                if (i > minP0) {
                    sum += i * (p1 - p0 + i);
                    ret[i - 1][i] = new Frac(i * (p1 - p0 + i), base);
                }
                if (i + 1 < n) {
                    sum += (p0 - i) * (p0 - i);
                    ret[i + 1][i] = new Frac((p0 - i) * (p0 - i), base);
                }
                ret[i][i] = new Frac(base - sum, base);
            }
            return ret;
        }

        public void solve(Scanner sc, PrintWriter pw) throws IOException {
            n = sc.nextInt();
            int k = sc.nextInt();
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = sc.nextInt();
                if (arr[i] == 0) {
                    p0++;
                } else {
                    p1++;
                }
            }
            if (p1 >= p0) minP0 = 0;
            else minP0 = p0 - p1;
            n = p0 + 1;
            int cnt0 = 0;
            for (int i = 0; i < p0; i++) {
                if (arr[i] == 0) cnt0++;
            }
            Frac[][] base = construct();
//            for (int i = 0; i < n; i++) {
//                for (int j = 0; j < n; j++) {
//                    System.err.print(base[i][j].toString() + " ");
//                }
//                System.err.println();
//            }
            Frac[][] powd = pow(base, k);
//            for (int i = 0; i < n; i++) {
//                for (int j = 0; j < n; j++) {
//                    System.err.print(powd[i][j].toString() + " ");
//                }
//                System.err.println();
//            }
            pw.println(powd[p0][cnt0].toVal());
        }
    }

    // template, actual code is in class Task.
    static long TIME_START, TIME_END;

    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
//        Scanner sc = new Scanner(new FileInputStream("Test.in"));
        PrintWriter pw = new PrintWriter(new BufferedOutputStream(System.out));
//        PrintWriter pw = new PrintWriter(new FileOutputStream("Test.out"));

        Runtime runtime = Runtime.getRuntime();
        long usedMemoryBefore = runtime.totalMemory() - runtime.freeMemory();
        TIME_START = System.currentTimeMillis();
        Task t = new Task();
        t.solve(sc, pw);
        TIME_END = System.currentTimeMillis();
        long usedMemoryAfter = runtime.totalMemory() - runtime.freeMemory();
        pw.close();
//        System.err.println("Memory increased: " + (usedMemoryAfter - usedMemoryBefore) / 1000000);
//        System.err.println("Time used: " + (TIME_END - TIME_START) + ".");
    }

    // Faster IO with BufferedReader wrapped with Scanner
//    static class Scanner {
//        StringTokenizer st;
//        BufferedReader br;
//
//        public Scanner(InputStream s) {
//            br = new BufferedReader(new InputStreamReader(s));
//        }
//
//        public Scanner(FileReader s) throws FileNotFoundException {
//            br = new BufferedReader(s);
//        }
//
//        public String next() throws IOException {
//            while (st == null || !st.hasMoreTokens())
//                st = new StringTokenizer(br.readLine());
//            return st.nextToken();
//        }
//
//        public int nextInt() throws IOException {
//            return Integer.parseInt(next());
//        }
//
//        public long nextLong() throws IOException {
//            return Long.parseLong(next());
//        }
//
//        public String nextLine() throws IOException {
//            return br.readLine();
//        }
//
//        public double nextDouble() throws IOException {
//            return Double.parseDouble(next());
//        }
//
//        public boolean ready() throws IOException {
//            return br.ready();
//        }
//    }
}