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.
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2000000;
long long a[MAXN];
long long l[MAXN], r[MAXN];
long long f[MAXN], g[MAXN], c[MAXN];
long long k, len;
int n, m;
int main() {
  scanf("%d %I64d", &n, &k);
  len = (long long)9e+18;
  for (int i = 0; i < n; i++) {
    scanf("%I64d %I64d", &l[i], &r[i]);
    len = min(len, r[i] - l[i]);
  }
  m = 0;
  for (int i = 1; i <= 19; i++) {
    for (int j = 0; j < (1 << i); j++) {
      long long x = 0;
      for (int k = i - 1; k >= 0; k--) {
        (x *= 10) += 4;
        if (j & (1 << k)) x += 3;
      }
      a[++m] = x;
    }
  }
  sort(r, r + n);
  for (int i = 0; i <= m + 1; i++) c[i] = 0;
  for (int i = 1, j = 0; i <= m; i++) {
    c[i] = c[i - 1];
    f[i] = c[i - 1] <= (k + 1) / (a[i] - a[i - 1])
               ? (a[i] - a[i - 1]) * c[i - 1] + f[i - 1]
               : k + 1;
    while (j < n && r[j] <= a[i]) {
      c[i]++;
      f[i] += a[i] - r[j];
      j++;
    }
    if (f[i] > k) f[i] = k + 1;
  }
  sort(l, l + n);
  reverse(l, l + n);
  for (int i = 0; i <= m + 1; i++) c[i] = 0;
  for (int i = m, j = 0; i >= 1; i--) {
    c[i] = c[i + 1];
    g[i] = c[i + 1] <= (k + 1) / (a[i + 1] - a[i])
               ? (a[i + 1] - a[i]) * c[i + 1] + g[i + 1]
               : k + 1;
    while (j < n && a[i] <= l[j]) {
      c[i]++;
      g[i] += l[j] - a[i];
      j++;
    }
    if (g[i] > k) g[i] = k + 1;
  }
  int ans = 0;
  for (int i = 1, j = 1; i <= m; i++) {
    while (g[i] + f[j] <= k && a[j] <= a[i] + len) j++;
    ans = max(ans, j - i);
  }
  printf("%d\n", ans);
  return 0;
}
