#include <bits/stdc++.h>
using namespace std;
const long long maxn = 2e6 + 55, inf = 1e18 + 180;
long long D[maxn], L[maxn], R[maxn], sumr[maxn], suml[maxn], tr[maxn], tl[maxn],
    mn, k, sz;
vector<long long> compress, lucky;
unordered_map<long long, long long> M;
long long check(long long l, long long r) {
  long long ans = 0;
  if (suml[D[l]] == -1 || sumr[D[r]] == -1) return inf;
  ans += suml[D[l]] + sumr[D[r]];
  return ans;
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n >> k;
  mn = inf;
  for (long long i = 0; i < n; i++) {
    cin >> L[i] >> R[i];
    mn = min(mn, R[i] - L[i]);
    compress.push_back(L[i]);
    compress.push_back(R[i]);
  }
  compress.push_back(0);
  compress.push_back(inf);
  for (long long i = 1; i <= 18; i++) {
    for (long long mask = 0; mask < (1 << i); mask++) {
      long long q = 0;
      for (long long j = i - 1; ~j; j--) {
        if (mask & (1 << j))
          q = q * 10 + 7;
        else
          q = q * 10 + 4;
      }
      compress.push_back(q);
      lucky.push_back(q);
    }
  }
  sort(compress.begin(), compress.end());
  compress.resize(unique(compress.begin(), compress.end()) - compress.begin());
  sz = compress.size();
  for (long long i = 0; i < sz; i++) M[compress[i]] = i;
  for (long long i = 0; i < n; i++) L[i] = M[L[i]], R[i] = M[R[i]];
  for (long long i = 0; i < lucky.size(); i++) {
    D[i] = M[lucky[i]];
  }
  for (long long i = 0; i < n; i++) {
    tr[R[i]]++;
    tl[L[i]]++;
  }
  for (long long i = 1; i < sz; i++) {
    tr[i] += tr[i - 1];
    sumr[i] = sumr[i - 1];
    if (sumr[i] == -1) continue;
    long long dist = compress[i] - compress[i - 1];
    if (tr[i - 1] > inf / dist) {
      sumr[i] = -1;
      continue;
    }
    sumr[i] += tr[i - 1] * dist;
    if (sumr[i] > inf) {
      sumr[i] = -1;
      continue;
    }
  }
  for (long long i = sz - 2; ~i; i--) {
    tl[i] += tl[i + 1];
    suml[i] = suml[i + 1];
    if (suml[i] == -1) continue;
    long long dist = compress[i + 1] - compress[i];
    if (tl[i + 1] > inf / dist) {
      suml[i] = -1;
      continue;
    }
    suml[i] += tl[i + 1] * dist;
    if (suml[i] > inf) {
      suml[i] = -1;
      continue;
    }
  }
  long long ptr1 = 0, ptr2 = 0, ans = 0;
  for (ptr2 = 0; ptr2 < lucky.size(); ptr2++) {
    while (ptr1 <= ptr2 &&
           (mn < lucky[ptr2] - lucky[ptr1] || check(ptr1, ptr2) > k))
      ptr1++;
    ans = max(ans, ptr2 - ptr1 + 1);
  }
  cout << ans;
}
