Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.

Petya has n number segments [l1; r1], [l2; r2], ..., [ln; rn]. During one move Petya can take any segment (let it be segment number i) and replace it with segment [li + 1; ri + 1] or [li - 1; ri - 1]. In other words, during one move Petya can shift any segment to the left or to the right by a unit distance. Petya calls a number full if it belongs to each segment. That is, number x is full if for any i (1 ≤ i ≤ n) the condition li ≤ x ≤ ri is fulfilled.

Petya makes no more than k moves. After that he counts the quantity of full lucky numbers. Find the maximal quantity that he can get.

Input

The first line contains two integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ 1018) — the number of segments and the maximum number of moves. Next n lines contain pairs of integers li and ri (1 ≤ li ≤ ri ≤ 1018).

Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the %I64d specificator.

Output

Print on the single line the single number — the answer to the problem.

Examples

Input

4 7
1 4
6 9
4 7
3 5


Output

1


Input

2 7
40 45
47 74


Output

2

Note

In the first sample Petya shifts the second segment by two units to the left (it turns into [4; 7]), after that number 4 becomes full.

In the second sample Petya shifts the first segment by two units to the right (it turns into [42; 47]), and shifts the second segment by three units to the left (it turns into [44; 71]), after that numbers 44 and 47 become full.
import java.util.*;
import java.io.*;
import java.lang.reflect.Array;
import java.math.*;
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);
        int t = 1;
        Task solver = new Task();
        while ((t --) > 0)
            solver.solve(in, out);
        out.close();
    }
}
class Task{
    static int N = 100005;
    static int M = (1 << 19) - 2;
    static long INF = 1000000000000000000L;
    long l[] = new long [N] , r[] = new long [N];
    long lucky[] = new long[M];
    BigInteger lsum[] = new BigInteger[M];
    BigInteger rsum[] = new BigInteger[M];
    void Init () {
        int c = 0;
        for (int i = 1 ; i <= 18 ; i ++) {
            for (int j = 0 ; j < (1 << i) ; j ++) {
                long t = 0;
                for (int k = 0 ; k < i ; k ++) {
                    if ((j & (1 << k)) != 0)
                        t = t * 10 + 7;
                    else t = t * 10 + 4;
                }
                lucky[c ++] = t;
            }
        }
        Arrays.sort(lucky);
    }
    void solve (InputReader cin , PrintWriter cout) {
        Init ();
        int n = cin.nextInt();
        long k = cin.nextLong();
        long minlen = INF;
        for (int i = 0 ; i < n ; i ++) {
            l[i] = cin.nextLong();
            r[i] = cin.nextLong();
            minlen = Math.min(minlen, r[i] - l[i] + 1);
        }
        Arrays.sort(l , 0 , n);
        Arrays.sort(r , 0 , n);
        BigInteger sum = BigInteger.ZERO;
        for (int i = M - 1 , j = n - 1 ; i >= 0 ; i --) {
            while (j >= 0 && lucky[i] <= l[j]) {
                sum = sum.add (BigInteger.valueOf(l[j]));
                j --;
            }
            lsum[i] = sum.subtract(BigInteger.valueOf(n - j - 1).multiply(BigInteger.valueOf(lucky[i])));
        }
        sum = BigInteger.ZERO;
        for (int i = 0 , j = 0 ; i < M ; i ++) {
            while (j < n && r[j] <= lucky[i]) {
                sum = sum.add (BigInteger.valueOf(r[j]));
                j ++;
            }
            rsum[i] = BigInteger.valueOf(lucky[i]).multiply(BigInteger.valueOf(j)).subtract(sum);
        }
        int ans = 0;
        for (int i = 0 , j = 0 ; i < M ; i ++) {
            while (i > j || j < M && lucky[j] - lucky[i] + 1 <= minlen && lsum[i].add (rsum[j]).compareTo(BigInteger.valueOf(k)) <= 0) j ++;
//          cout.println (i + " " + j);
//          if (i > 10) break;
            ans = Math.max (ans , j - i);
        }
        cout.println(ans);
    }
}
class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;
    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream));
        tokenizer = null;
    }
    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }
    public int nextInt() {
        return Integer.parseInt(next());
    }
    public long nextLong() {
        return Long.parseLong(next());
    }
    public double nextDouble() {
        return Double.parseDouble(next());
    }
    public BigInteger nextBigInteger() {
        return new BigInteger(next());
    }
}