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 long long ooo = 1000000001;
const long long oo = ooo * ooo;
const int V = 100100;
struct Node {
  long long l, r;
} q[V];
bool LE(Node x, Node y) { return x.l < y.l; }
bool RI(Node x, Node y) { return x.r < y.r; }
int n, N, i, j, ct;
long long k;
long long p[V * 10];
long long le[V * 10], ri[V * 10];
int main() {
  while (cin >> n >> k) {
    long long mi = oo;
    for (i = 0; i < n; i++) {
      cin >> q[i].l >> q[i].r;
      mi = min(mi, q[i].r - q[i].l);
    }
    ct = 0;
    for (N = 1; N <= 18; N++) {
      for (i = 0; i < (1 << N); i++) {
        long long te = 0;
        for (j = 0; j < N; j++) {
          te *= 10;
          if (i & (1 << j))
            te += 4;
          else
            te += 7;
        }
        p[ct++] = te;
      }
    }
    sort(p, p + ct);
    sort(q, q + n, LE);
    int pt = n - 1;
    le[ct - 1] = 0;
    while (pt >= 0 && p[ct - 1] < q[pt].l) {
      if (oo - le[ct - 1] < q[pt].l - p[ct - 1])
        le[ct - 1] = oo;
      else
        le[ct - 1] += q[pt].l - p[ct - 1];
      pt--;
    }
    for (i = ct - 2; i >= 0; i--) {
      le[i] = le[i + 1];
      if ((double)(oo - le[i]) < (double)(n - 1 - pt) * (p[i + 1] - p[i]))
        le[i] = oo;
      else
        le[i] += (n - 1 - pt) * (p[i + 1] - p[i]);
      while (pt >= 0 && p[i] < q[pt].l) {
        if (oo - le[i] < q[pt].l - p[i])
          le[i] = oo;
        else
          le[i] += q[pt].l - p[i];
        pt--;
      }
    }
    sort(q, q + n, RI);
    pt = 0;
    ri[0] = 0;
    while (pt < n && p[0] > q[pt].r) {
      if (oo - ri[0] < p[0] - q[pt].r)
        ri[0] = oo;
      else
        ri[0] += p[0] - q[pt].r;
      pt++;
    }
    for (i = 1; i < ct; i++) {
      ri[i] = ri[i - 1];
      if ((double)(oo - ri[i]) < (double)(pt) * (p[i] - p[i - 1]))
        ri[i] = oo;
      else
        ri[i] += (pt) * (p[i] - p[i - 1]);
      while (pt < n && p[i] > q[pt].r) {
        if (oo - ri[i] < p[i] - q[pt].r)
          ri[i] = oo;
        else
          ri[i] += p[i] - q[pt].r;
        pt++;
      }
    }
    int ans = 0;
    pt = 0;
    for (i = 0; i < ct; i++) {
      if (le[i] == oo) continue;
      int lo, up, mid;
      while (pt < ct && p[i] >= p[pt] - mi) pt++;
      lo = i - 1;
      up = pt;
      while (lo + 1 < up) {
        mid = (lo + up) / 2;
        if (ri[mid] == oo || le[i] > k - ri[mid])
          up = mid;
        else
          lo = mid;
      }
      ans = max(ans, lo - i + 1);
    }
    printf("%d\n", ans);
  }
}
