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

public class Solution {
    BigInteger[] prepare(long[] ends) {
        Arrays.sort(ends);
        int n = ends.length;
        BigInteger[] sum = new BigInteger[n + 1];
        sum[n] = BigInteger.ZERO;
        for (int i = n - 1; i >= 0; -- i) {
            sum[i] = sum[i + 1].add(BigInteger.valueOf(ends[i]));
        }
        return sum;
    }
    
    final static int M = (1 << 19) - 2;

    BigInteger getCost(long[] ends, BigInteger[] sum, long x) {
        int n = ends.length;
        int low = 0;
        int high = n;
        while (low < high) {
            int middle = low + high >> 1;
            if (ends[middle] <= x) {
                low = middle + 1;
            } else {
                high = middle;
            }
        }
        return sum[high].subtract(BigInteger.valueOf(x).multiply(BigInteger.valueOf(n - high)));
    }

    public void run() {
        try {
            long[] numbers = new long[M];
            if (true) {
                int total = 0;
                for (int length = 1; length <= 18; ++ length) {
                    for (int mask = 0; mask < 1 << length; ++ mask) {
                        long now = 0;
                        for (int i = 1; i <= length; ++ i) {
                            now *= 10;
                            now += (mask >> (length - i) & 1) == 0 ? 4 : 7;
                        }
                        numbers[total ++] = now;
                    }
                }
            }
            int n = reader.nextInt();
            long k = reader.nextLong();
            long[] left = new long[n];
            long[] right = new long[n];
            long maxLength = Long.MAX_VALUE;
            for (int i = 0; i < n; ++ i) {
                left[i] = reader.nextLong();
                right[i] = reader.nextLong();
                maxLength = Math.min(maxLength, right[i] - left[i]);
                right[i] *= -1;
            }
            BigInteger[] leftSum = prepare(left);
            BigInteger[] rightSum = prepare(right);
            int answer = 0;
            for (int i = 0, j = 0; j < M; ++ j) {
                while (numbers[j] - numbers[i] > maxLength) {
                    i ++;
                }
                while (i <= j) {
                    BigInteger cost = getCost(left, leftSum, numbers[i])
                                 .add(getCost(right, rightSum, -numbers[j]));
                    if (cost.compareTo(BigInteger.valueOf(k)) <= 0) {
                        break;
                    }
                    i ++;
                }
                answer = Math.max(answer, j - i + 1);
            }
            writer.println(answer);
        } catch (IOException ex) {
        }
        writer.close();
    }

    InputReader reader;
    PrintWriter writer;

    Solution() {
        reader = new InputReader();
        writer = new PrintWriter(System.out);
    }

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

}

class InputReader {
    BufferedReader reader;
    StringTokenizer tokenizer;

    InputReader() {
        reader = new BufferedReader(new InputStreamReader(System.in));
        tokenizer = new StringTokenizer("");
    }

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

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

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