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>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
const long long inf = 2000000000000000000LL;
vector<long long> a;
void gen(long long current) {
  if (current > inf) {
    return;
  }
  if (current > 0) {
    a.push_back(current);
  }
  gen(current * 10LL + 4LL);
  gen(current * 10LL + 7LL);
}
struct Long {
  long long a, b;
  Long(long long n) : a(0), b(n) {}
  Long() : a(0), b(0) {}
  bool operator<(const Long &other) const {
    return make_pair(a, b) < make_pair(other.a, other.b);
  }
  void add(const Long &other) {
    a += other.a;
    b += other.b;
    if (b >= inf) {
      b -= inf;
      ++a;
    }
  }
  void sub(const Long &other) {
    a -= other.a;
    b -= other.b;
    if (b < 0) {
      b += inf;
      --a;
    }
  }
};
Long mul(const Long &A, long long k) {
  if (k == 0) {
    return Long();
  }
  if (k == 1) {
    return A;
  }
  if (A.b < (4LL * inf) / k) {
    Long B = A;
    B.a *= k;
    B.b *= k;
    if (B.b >= inf) {
      B.a += B.b / inf;
      B.b %= inf;
    }
    return B;
  }
  Long B = mul(A, k / 2);
  B.add(B);
  if (k % 2 == 1) {
    B.add(A);
  }
  return B;
}
const int maxN = 110000;
long long n, k, m;
long long l[maxN], r[maxN];
Long sl[maxN], sr[maxN];
bool check(int cnt) {
  if (cnt == 0) {
    return true;
  }
  int indexR = 0;
  int indexL = 0;
  for (int i = 0; i + cnt <= a.size(); ++i) {
    if (a[i + cnt - 1] - a[i] + 1 > m) {
      continue;
    }
    Long L = a[i];
    Long R = a[i + cnt - 1];
    Long sum;
    while (indexR < n && r[indexR] <= a[i + cnt - 1]) {
      ++indexR;
    }
    sum = mul(R, indexR);
    if (indexR > 0) {
      sum.sub(sr[indexR - 1]);
    }
    if (Long(k) < sum) {
      continue;
    }
    while (indexL < n && l[indexL] < a[i]) {
      ++indexL;
    }
    if (indexL < n) {
      sum.add(sl[n - 1]);
      if (indexL != 0) {
        sum.sub(sl[indexL - 1]);
      }
      sum.sub(mul(L, n - indexL));
    }
    if (sum < Long(k + 1)) {
      return true;
    }
  }
  return false;
}
int main() {
  gen(0);
  sort(a.begin(), a.end());
  cin >> n >> k;
  m = inf;
  for (int i = 0; i < n; ++i) {
    cin >> l[i] >> r[i];
    m = min(m, r[i] - l[i] + 1LL);
  }
  sort(l, l + n);
  sort(r, r + n);
  for (int i = 0; i < n; ++i) {
    sl[i] = l[i];
    if (i > 0) {
      sl[i].add(sl[i - 1]);
    }
    sr[i] = r[i];
    if (i > 0) {
      sr[i].add(sr[i - 1]);
    }
  }
  int left_bound = 0, right_bound = a.size();
  while (right_bound - left_bound > 1) {
    int middle = (left_bound + right_bound) / 2;
    if (check(middle)) {
      left_bound = middle;
    } else {
      right_bound = middle;
    }
  }
  if (check(right_bound)) {
    cout << right_bound << endl;
  } else {
    cout << left_bound << endl;
  }
  return 0;
}
