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<long long> lucky;
void rec(int n, long long cur) {
  if (cur) lucky.push_back(cur);
  if (n > 0) {
    rec(n - 1, cur * 10 + 4);
    rec(n - 1, cur * 10 + 7);
  }
}
struct BigInt {
  static const int LEN = 4;
  static const int MOD = int(1e8);
  long long a[LEN];
  BigInt(long long x = 0) {
    for (int i = 0; i < LEN; ++i) {
      a[i] = x % MOD;
      x /= MOD;
    }
  }
  BigInt& operator+=(const BigInt& o) {
    long long carry = 0;
    for (int i = 0; i < LEN; ++i) {
      carry += a[i] + o.a[i];
      a[i] = carry % MOD;
      carry /= MOD;
    }
    return *this;
  }
  BigInt operator+(const BigInt& o) const {
    BigInt c = *this;
    return c += o;
  }
  BigInt& operator=(const BigInt& o) {
    memcpy(a, o.a, sizeof a);
    return *this;
  }
  BigInt& operator-=(const BigInt& o) {
    bool borrow = false;
    for (int i = 0; i < LEN; ++i) {
      if (borrow) {
        --a[i];
        borrow = false;
      }
      if (a[i] < o.a[i]) {
        a[i] += MOD;
        borrow = true;
      }
      a[i] -= o.a[i];
    }
    return *this;
  }
  BigInt operator-(const BigInt& o) const {
    BigInt c = *this;
    return c -= o;
  }
  BigInt operator*(const BigInt& o) const {
    BigInt c;
    for (int i = 0; i < LEN; ++i) {
      for (int j = 0; i + j < LEN; ++j) {
        c.a[i + j] += a[i] * o.a[j];
      }
    }
    for (int i = 0; i < LEN; ++i) {
      if (c.a[i] >= MOD) {
        c.a[i + 1] += c.a[i] / MOD;
        c.a[i] %= MOD;
      }
    }
    return c;
  }
  bool operator<=(const BigInt& o) const {
    for (int i = LEN - 1; i >= 0; --i) {
      if (a[i] < o.a[i]) return true;
      if (a[i] > o.a[i]) return false;
    }
    return true;
  }
};
int main() {
  rec(18, 0);
  sort(lucky.begin(), lucky.end());
  int n;
  long long k;
  cin >> n >> k;
  vector<long long> l(n), r(n);
  long long minl = LONG_LONG_MAX;
  for (int i = 0; i < n; ++i) {
    cin >> l[i] >> r[i];
    minl = min(minl, r[i] - l[i]);
  }
  sort(l.begin(), l.end());
  sort(r.begin(), r.end());
  int nL = lucky.size();
  vector<BigInt> lc(nL), rc(nL);
  int cur = l.size(), c = 0;
  BigInt s = 0;
  for (int i = nL - 1; i >= 0; --i) {
    while (cur > 0 && l[cur - 1] >= lucky[i]) {
      --cur;
      ++c;
      s += l[cur];
    }
    lc[i] = s - BigInt(c) * lucky[i];
  }
  s = c = 0;
  cur = -1;
  for (int i = 0; i < nL; ++i) {
    while (cur + 1 < r.size() && r[cur + 1] <= lucky[i]) {
      ++cur;
      ++c;
      s += r[cur];
    }
    rc[i] = BigInt(c) * lucky[i] - s;
  }
  int j = -1, ans = 0;
  for (int i = 0; i < nL; ++i) {
    while (j + 1 < nL && lucky[j + 1] - lucky[i] <= minl &&
           lc[i] + rc[j + 1] <= k)
      ++j;
    if (lucky[j] - lucky[i] <= minl && lc[i] + rc[j] <= k)
      ans = max(ans, j - i + 1);
  }
  cout << ans << endl;
  return 0;
}
