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;
vector<unsigned long long> lucky;
void gen(unsigned long long x) {
  if (x > 1000000000000000000L) return;
  lucky.push_back(x);
  gen(x * 10 + 4);
  gen(x * 10 + 7);
}
int main() {
  gen(4);
  gen(7);
  lucky.push_back(4444444444444444444L);
  sort(lucky.begin(), lucky.end());
  int n;
  unsigned long long k;
  cin >> n >> k;
  vector<pair<unsigned long long, unsigned long long> > a, b;
  for (int i = 0; i < n; ++i) {
    unsigned long long d1, d2;
    cin >> d1 >> d2;
    a.push_back(make_pair(d1, d2));
    b.push_back(make_pair(d2, d1));
  }
  sort(a.rbegin(), a.rend());
  sort(b.begin(), b.end());
  int p = 0;
  unsigned long long c = 0;
  for (int i = 0; i < n; ++i) {
    c += a[i].first;
  }
  unsigned long long prev = 0;
  int d = n;
  c = 0;
  prev = 4444444444444444445L;
  d = 0;
  p = 0;
  vector<unsigned long long> zz;
  for (int i = lucky.size() - 1; i >= 0; --i) {
    if (d > 0) {
      if (prev - lucky[i] > k / d) c = k + 1;
      if (c <= k) c += d * (prev - lucky[i]);
      if (c > k) {
        c = k + 1;
      }
    }
    while ((p < n) && (a[p].first >= lucky[i])) {
      d += 1;
      if (c <= k) c += a[p].first - lucky[i];
      if (c > k) {
        c = k + 1;
      }
      p += 1;
    }
    prev = lucky[i];
    zz.push_back(c);
  }
  reverse(zz.begin(), zz.end());
  c = 0;
  prev = 0;
  d = 0;
  p = 0;
  vector<unsigned long long> zz2;
  for (int i = 0; i < lucky.size(); ++i) {
    if (d > 0) {
      if (prev - lucky[i] > k / d) c = k + 1;
      if (c <= k) c += d * (lucky[i] - prev);
      if (c > k) {
        c = k + 1;
      }
    }
    while ((p < n) && (b[p].first <= lucky[i])) {
      d += 1;
      if (c <= k) c += lucky[i] - b[p].first;
      if (c > k) {
        c = k + 1;
      }
      p += 1;
    }
    prev = lucky[i];
    zz2.push_back(c);
  }
  unsigned long long minlen = 4444444444444444444L;
  for (int i = 0; i < n; ++i) {
    minlen = min(minlen, a[i].second - a[i].first + 1);
  }
  int ans = 0;
  for (int i = 0; i < lucky.size(); ++i) {
    if (zz[i] + zz2[i] > k)
      continue;
    else {
      int r = lucky.size() - 1;
      int l = i;
      while (r - l > 1) {
        int t = (r + l) / 2;
        if ((lucky[t] - lucky[i] + 1 > minlen) || (zz[i] + zz2[t] > k))
          r = t;
        else
          l = t;
      }
      if ((lucky[r] - lucky[i] + 1 <= minlen) && (zz[i] + zz2[r] <= k))
        ans = max(ans, r - i + 1);
      if ((lucky[l] - lucky[i] + 1 <= minlen) && (zz[i] + zz2[l] <= k)) {
        ans = max(ans, l - i + 1);
      }
    }
  }
  cout << ans << endl;
  return 0;
}
