#include <bits/stdc++.h>
using namespace std;
bool check(long long n, long long pos) { return (n & (1ll << pos)) >> pos; }
const long long M = 1000010;
struct data {
  long long first, second, t;
  data(long long a = 0, long long b = 0, long long c = 0) {
    first = a;
    second = b;
    t = c;
  }
};
long long L[M], R[M];
vector<data> A;
long long limit;
long long mindif;
vector<long long> lucky;
bool compleft(data &a, data &b) {
  if (a.second == b.second)
    return a.t > b.t;
  else
    return a.second < b.second;
}
bool compright(data &a, data &b) {
  if (a.first == b.first)
    return a.t < b.t;
  else
    return a.first < b.first;
}
long long evaluate(long long a, long long b, long long c) {
  if (a == 1000000000000000011) return 1000000000000000011;
  double costcost = a, bb = b, cc = c, infinf = 1000000000000000011;
  if ((costcost + bb * cc) >= infinf) return 1000000000000000011;
  return a + b * c;
}
bool ispossible(long long len) {
  if (len == 0) return true;
  for (long long i = 0, j = i + len - 1; j < lucky.size(); i++, j++) {
    if (L[j] + R[i] <= limit && lucky[j] - lucky[i] <= mindif) return true;
  }
  return false;
}
int main() {
  ios_base::sync_with_stdio(false);
  long long i, j, k, n;
  long long DMAX = 18;
  for (i = 1; i <= DMAX; i++) {
    for (j = 0; j < (1ll << i); j++) {
      char a[22];
      for (k = 0; k < i; k++) a[k] = check(j, k) ? '4' : '7';
      a[i] = '\0';
      A.push_back(data(atoll(a), atoll(a), 0));
    }
  }
  mindif = 1000000000000000011;
  scanf("%lld%lld", &n, &limit);
  for (i = 0; i < n; i++) {
    scanf("%lld%lld", &j, &k);
    A.push_back(data(j, k, 1));
    mindif = min(mindif, k - j);
  }
  sort((A).begin(), (A).end(), compleft);
  long long cost = 0, seg = A[0].t;
  n = 0;
  if (A[0].t == 0) L[n++] = 0, lucky.push_back(A[0].first);
  for (i = 1; i < A.size(); i++) {
    cost = evaluate(cost, (A[i].second - A[i - 1].second), seg);
    seg += A[i].t;
    if (A[i].t == 0) L[n++] = cost, lucky.push_back(A[i].first);
  }
  sort((A).begin(), (A).end(), compright);
  cost = 0, seg = A.back().t;
  j = n - 1;
  if (A.back().t == 0) R[j--] = 0;
  for (i = A.size() - 2; i >= 0; i--) {
    cost = evaluate(cost, (A[i + 1].first - A[i].first), seg);
    seg += A[i].t;
    if (A[i].t == 0) R[j--] = cost;
  }
  long long first = 0, h = n;
  while (first < h) {
    long long m = (first + h + 1) / 2;
    if (ispossible(m))
      first = m;
    else
      h = m - 1;
  }
  printf("%lld\n", first);
  return 0;
}
