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;
struct BigInteger {
  static const int LEN = 4;
  static const long long MOD;
  long long a[LEN];
  explicit BigInteger(long long x) {
    fill(a + 1, a + LEN, 0LL);
    a[0] = x;
    for (int i = 0; a[i] >= MOD; ++i) {
      a[i + 1] += a[i] / MOD;
      a[i] %= MOD;
    }
  }
  BigInteger(const BigInteger& o) { copy(o.a, o.a + LEN, a); }
  void operator+=(const BigInteger& o) {
    for (int i = 0; i < LEN; ++i) {
      a[i] += o.a[i];
      while (a[i] >= MOD) {
        ++a[i + 1];
        a[i] -= MOD;
      }
    }
  }
  void operator-=(const BigInteger& o) {
    for (int i = 0; i < LEN; ++i) {
      a[i] -= o.a[i];
      while (a[i] < 0) {
        --a[i + 1];
        a[i] += MOD;
      }
    }
  }
  bool operator<=(const BigInteger& o) {
    for (int i = LEN - 1; i >= 0; --i) {
      if (a[i] != o.a[i]) {
        return a[i] < o.a[i];
      }
    }
    return true;
  }
  void dump() const {
    for (int i = LEN - 1; i >= 0; --i) {
      printf("%08lld,", a[i]);
    }
    puts("");
  }
};
BigInteger operator*(const BigInteger& a, const BigInteger& b) {
  BigInteger c(0);
  for (int i = 0; i < BigInteger::LEN; ++i) {
    for (int j = 0; j <= i; ++j) {
      c.a[i] += a.a[j] * b.a[i - j];
    }
    if (c.a[i] >= BigInteger::MOD) {
      c.a[i + 1] += c.a[i] / BigInteger::MOD;
      c.a[i] %= BigInteger::MOD;
    }
  }
  return c;
}
const long long BigInteger::MOD = 100000000LL;
const long long INF = 4444444444444444444LL;
vector<long long> lucky;
void gen(int n, long long m) {
  lucky.push_back(m);
  if (n > 0) {
    gen(n - 1, m * 10 + 4);
    gen(n - 1, m * 10 + 7);
  }
}
void init() {
  lucky.clear();
  gen(18, 0);
  lucky.push_back(INF);
  sort(lucky.begin(), lucky.end());
}
const int MAXN = 100100;
int main() {
  int n, ans;
  long long m, l, r, d, cl, cr;
  multiset<long long> w;
  vector<pair<long long, long long> > v;
  init();
  cin >> n >> m;
  BigInteger bm(m);
  BigInteger bs(0);
  d = lucky.back();
  for (int i = 0; i < n; ++i) {
    cin >> l >> r;
    bs += BigInteger(l);
    d = min(d, r - l);
    v.push_back({l, r});
  }
  sort(v.rbegin(), v.rend());
  ans = 0;
  l = r = 1;
  cl = n;
  cr = 0;
  while (l < (int)lucky.size() && r < (int)lucky.size()) {
    while (!v.empty() && v.back().first <= lucky[l]) {
      bs -= BigInteger(v.back().first - lucky[l - 1]);
      w.insert(v.back().second);
      v.pop_back();
      --cl;
    }
    bs -= BigInteger(cl) * BigInteger(lucky[l] - lucky[l - 1]);
    while (r < (int)lucky.size() && lucky[r] - lucky[l] <= d && bs <= bm) {
      bs += BigInteger(cr) * BigInteger(lucky[r] - lucky[r - 1]);
      while (!w.empty() && *w.begin() < lucky[r]) {
        bs += BigInteger(lucky[r] - *w.begin());
        w.erase(w.begin());
        ++cr;
      }
      if (bs <= bm) {
        ++r;
        ans = max(ans, (int)(r - l));
      }
    }
    ++l;
  }
  printf("%d\n", ans);
  return 0;
}
