#include <bits/stdc++.h>
using namespace std;
class MPI {
 public:
  vector<long long int> MPI_VALUE;
  bool MPI_SIGN;
  MPI(const string &mpi_s) {
    MPI_SIGN = false;
    if (((long long int)(mpi_s).size())) {
      if (mpi_s[0] == '-') MPI_SIGN = true;
      for (long long int i = ((long long int)(mpi_s).size()) - 1;
           ((mpi_s[0] == '-') ? 1 : 0) <= i; i -= 6) {
        long long int mpi_sum = 0;
        long long int mpi_base = 1;
        for (long long int j = 0; j < ((long long int)(6)); j++)
          if (((mpi_s[0] == '-') ? 1 : 0) <= i - j) {
            mpi_sum += (mpi_s[i - j] - '0') * mpi_base;
            mpi_base *= 10;
          }
        MPI_VALUE.push_back(mpi_sum);
      }
    }
    mpi_reform(*this);
  }
  MPI(const vector<long long int> &mpi_vec) {
    MPI_SIGN = false;
    MPI_VALUE = mpi_vec;
    mpi_reform(*this);
  }
  MPI(int mpi_val) {
    MPI_SIGN = false;
    if (mpi_val < 0) {
      mpi_val = -mpi_val;
      MPI_SIGN = true;
    }
    while (mpi_val) {
      MPI_VALUE.push_back(mpi_val % 1000000);
      mpi_val /= 1000000;
    }
    mpi_reform(*this);
  }
  MPI(long long int mpi_val) {
    MPI_SIGN = false;
    if (mpi_val < 0) {
      mpi_val = -mpi_val;
      MPI_SIGN = true;
    }
    while (mpi_val) {
      MPI_VALUE.push_back(mpi_val % 1000000);
      mpi_val /= 1000000;
    }
    mpi_reform(*this);
  }
  MPI(bool mpi_need0, bool mpi_need1) { MPI_SIGN = false; }
  MPI() {
    MPI_SIGN = false;
    MPI_VALUE.push_back(0);
  }
  string to_string() const {
    string mpi_res = "";
    long long int mpi_p10[6 + 1];
    for (long long int i = 0; i < ((long long int)(6 + 1)); i++)
      mpi_p10[i] = (i) ? (mpi_p10[i - 1] * 10) : 1;
    for (long long int i = ((long long int)(MPI_VALUE).size()) - 1; 0 <= i; i--)
      for (long long int j = 0; j < ((long long int)(6)); j++) {
        long long int mpi_tmp =
            (MPI_VALUE[i] % mpi_p10[6 - j]) / mpi_p10[6 - j - 1];
        if (((long long int)(mpi_res).size()) || mpi_tmp)
          mpi_res += string(1, '0' + mpi_tmp);
      }
    if (((long long int)(mpi_res).size()) == 0)
      mpi_res += "0";
    else if (MPI_SIGN)
      mpi_res = "-" + mpi_res;
    return mpi_res;
  }
  long long int to_long() const {
    long long int mpi_res = 0;
    long long int mpi_base = 1;
    for (long long int i = 0;
         i < ((long long int)(((long long int)(MPI_VALUE).size()))); i++) {
      mpi_res += MPI_VALUE[i] * mpi_base;
      mpi_base *= 1000000;
    }
    if (MPI_SIGN) mpi_res = -mpi_res;
    return mpi_res;
  }
  long long int size() const {
    long long int mpi_res = (((long long int)(MPI_VALUE).size()) - 1) * 6;
    long long int mpi_tmp = MPI_VALUE.back();
    while (mpi_tmp) {
      mpi_res++;
      mpi_tmp /= 10;
    }
    return mpi_res;
  }
  static MPI mpi_abs_add(const MPI &mpi0, const MPI &mpi1) {
    MPI mpi_res(false, false);
    long long int carry = 0;
    for (long long int i = 0;
         i < ((long long int)(max(((long long int)(mpi0.MPI_VALUE).size()),
                                  ((long long int)(mpi1.MPI_VALUE).size()))));
         i++) {
      long long int mpi_t0 = (i < ((long long int)(mpi0.MPI_VALUE).size()))
                                 ? (mpi0.MPI_VALUE[i])
                                 : 0;
      long long int mpi_t1 = (i < ((long long int)(mpi1.MPI_VALUE).size()))
                                 ? (mpi1.MPI_VALUE[i])
                                 : 0;
      long long int mpi_t = mpi_t0 + mpi_t1 + carry;
      mpi_res.MPI_VALUE.push_back(mpi_t % 1000000);
      carry = mpi_t / 1000000;
    }
    if (carry) mpi_res.MPI_VALUE.push_back(carry);
    mpi_reform(mpi_res);
    return mpi_res;
  }
  static MPI mpi_abs_sub_sub(const MPI &mpi0, const MPI &mpi1) {
    MPI mpi_res(false, false);
    mpi_res.MPI_VALUE = mpi0.MPI_VALUE;
    long long int carry = 0;
    for (long long int i = 0;
         i < ((long long int)(mpi1.MPI_VALUE).size()) || carry; i++) {
      mpi_res.MPI_VALUE[i] -= carry;
      carry = 0;
      if (i < ((long long int)(mpi1.MPI_VALUE).size()))
        mpi_res.MPI_VALUE[i] = mpi_res.MPI_VALUE[i] - mpi1.MPI_VALUE[i];
      if (mpi_res.MPI_VALUE[i] < 0) {
        carry++;
        mpi_res.MPI_VALUE[i] += 1000000;
      }
    }
    mpi_reform(mpi_res);
    return mpi_res;
  }
  static MPI mpi_abs_sub(const MPI &mpi0, const MPI &mpi1) {
    if (!mpi_abs_gt(mpi0, mpi1)) return mpi_abs_sub_sub(mpi0, mpi1);
    MPI mpi_res = mpi_abs_sub_sub(mpi1, mpi0);
    mpi_res.MPI_SIGN = !mpi_res.MPI_SIGN;
    return mpi_res;
  }
  static MPI mpi_abs_mul(const MPI &mpi0, const MPI &mpi1) {
    MPI mpi_res(false, false);
    mpi_res.MPI_VALUE =
        vector<long long int>(((long long int)(mpi0.MPI_VALUE).size()) +
                                  ((long long int)(mpi1.MPI_VALUE).size()),
                              0);
    for (long long int i = 0;
         i < ((long long int)(((long long int)(mpi0.MPI_VALUE).size()))); i++)
      if (mpi0.MPI_VALUE[i]) {
        for (long long int j = 0;
             j < ((long long int)(((long long int)(mpi1.MPI_VALUE).size())));
             j++) {
          mpi_res.MPI_VALUE[i + j] += mpi0.MPI_VALUE[i] * mpi1.MPI_VALUE[j];
        }
      }
    mpi_add_mul_reform(mpi_res);
    return mpi_res;
  }
  MPI operator+(const MPI &mpi_var) {
    bool b0 = MPI_SIGN, b1 = mpi_var.MPI_SIGN;
    if (!b0 && !b1) return mpi_abs_add(*this, mpi_var);
    if (!b0 && b1) return mpi_abs_sub(*this, mpi_var);
    if (b0 && !b1) return mpi_abs_sub(mpi_var, *this);
    MPI mpi_res = mpi_abs_add(*this, mpi_var);
    mpi_res.MPI_SIGN = !mpi_res.MPI_SIGN;
    return mpi_res;
  }
  MPI operator-(const MPI &mpi_var) {
    bool b0 = MPI_SIGN, b1 = mpi_var.MPI_SIGN;
    if (!b0 && !b1) return mpi_abs_sub(*this, mpi_var);
    if (!b0 && b1) return mpi_abs_add(*this, mpi_var);
    if (b0 && b1) return mpi_abs_sub(mpi_var, *this);
    MPI mpi_res = mpi_abs_add(*this, mpi_var);
    mpi_res.MPI_SIGN = !mpi_res.MPI_SIGN;
    return mpi_res;
  }
  MPI operator*(const MPI &mpi_var) {
    bool b0 = MPI_SIGN, b1 = mpi_var.MPI_SIGN;
    if (b0 && b1) return mpi_abs_mul(*this, mpi_var);
    if (!b0 && !b1) return mpi_abs_mul(*this, mpi_var);
    MPI mpi_res = mpi_abs_mul(*this, mpi_var);
    mpi_res.MPI_SIGN = !mpi_res.MPI_SIGN;
    return mpi_res;
  }
  friend std::ostream &operator<<(std::ostream &os, const MPI &mpi_var) {
    os << mpi_var.to_string();
    return os;
  }
  friend std::istream &operator>>(std::istream &is, MPI &mpi_var) {
    string mpi_str;
    is >> mpi_str;
    mpi_var = MPI(mpi_str);
    return is;
  }
  static void mpi_subst(MPI &mpi_from, const MPI &mpi_base,
                        long long int mpi_cons, long long int mpi_shift) {
    long long int carry = 0;
    for (long long int i = 0;
         i + mpi_shift < ((long long int)(mpi_from.MPI_VALUE).size()); i++) {
      mpi_from.MPI_VALUE[mpi_shift + i] -= carry;
      carry = 0;
      if (i < ((long long int)(mpi_base.MPI_VALUE).size())) {
        carry = (mpi_base.MPI_VALUE[i] * mpi_cons) / 1000000;
        mpi_from.MPI_VALUE[mpi_shift + i] -=
            (mpi_base.MPI_VALUE[i] * mpi_cons) % 1000000;
      }
      while (mpi_from.MPI_VALUE[mpi_shift + i] < 0) {
        carry++;
        mpi_from.MPI_VALUE[mpi_shift + i] += 1000000;
      }
    }
  }
  static bool mpi_can_sub(const MPI &mpi_from, const MPI &mpi_base,
                          long long int mpi_cons, long long int mpi_shift) {
    long long int carry = 0;
    for (long long int i = 0;
         i + mpi_shift < ((long long int)(mpi_from.MPI_VALUE).size()); i++) {
      long long int mpi_tmp = carry;
      if (i < ((long long int)(mpi_base.MPI_VALUE).size()))
        mpi_tmp += mpi_base.MPI_VALUE[i] * mpi_cons;
      long long int mpi_dif = (mpi_tmp - mpi_from.MPI_VALUE[i + mpi_shift]);
      if (mpi_dif < 0)
        carry = 0;
      else
        carry = ((mpi_dif % 1000000) ? 1 : 0) + mpi_dif / 1000000;
    }
    return carry == 0;
  }
  static MPI mpi_abs_div_small(const MPI &mpi_den, const MPI &mpi_num,
                               bool is_div) {
    MPI mpi_ans(false, false);
    MPI mpi_rem(mpi_den.MPI_VALUE);
    mpi_ans.MPI_VALUE =
        vector<long long int>(((long long int)(mpi_rem.MPI_VALUE).size()), 0);
    long long int mpi_cons = abs(mpi_num.to_long()), carry = 0;
    for (long long int i = ((long long int)(mpi_rem.MPI_VALUE).size()) - 1;
         0 <= i; i--) {
      mpi_rem.MPI_VALUE[i] += carry * 1000000;
      carry = mpi_rem.MPI_VALUE[i] % mpi_cons;
      mpi_ans.MPI_VALUE[i] = mpi_rem.MPI_VALUE[i] / mpi_cons;
    }
    if (!is_div) return MPI(carry);
    mpi_reform(mpi_ans);
    return mpi_ans;
  }
  static MPI mpi_abs_div(const MPI &mpi_den, const MPI &mpi_num, bool is_div) {
    if (mpi_abs_gt(mpi_num, 1000000))
      return mpi_abs_div_small(mpi_den, mpi_num, is_div);
    MPI mpi_ans(0);
    MPI mpi_rem(mpi_den.MPI_VALUE);
    mpi_ans.MPI_VALUE =
        vector<long long int>(((long long int)(mpi_rem.MPI_VALUE).size()), 0);
    long long int mpi_num_pos = ((long long int)(mpi_num.MPI_VALUE).size()) - 1;
    long long int mpi_num_n = mpi_num.MPI_VALUE[mpi_num_pos];
    if (mpi_num_n * 1000000 < 1000000000000000000ll / 1000000 &&
        1 <= mpi_num_pos) {
      mpi_num_n = mpi_num_n * 1000000 + mpi_num.MPI_VALUE[--mpi_num_pos];
    }
    while (!mpi_abs_gt(mpi_rem, mpi_num)) {
      long long int mpi_rem_pos =
          ((long long int)(mpi_rem.MPI_VALUE).size()) - 1;
      long long int mpi_rem_n = mpi_rem.MPI_VALUE[mpi_rem_pos];
      while (mpi_rem_n < mpi_num_n) {
        mpi_rem_n = mpi_rem_n * 1000000 + mpi_rem.MPI_VALUE[--mpi_rem_pos];
      }
      long long int mpi_tmp = mpi_rem_n / mpi_num_n;
      long long int mpi_dif = mpi_rem_pos - mpi_num_pos;
      while (!mpi_can_sub(mpi_rem, mpi_num, mpi_tmp, mpi_dif)) mpi_tmp--;
      if (mpi_tmp == 0) {
        mpi_rem_n = mpi_rem_n * 1000000 + mpi_rem.MPI_VALUE[--mpi_rem_pos];
        mpi_tmp = mpi_rem_n / mpi_num_n;
        mpi_dif = mpi_rem_pos - mpi_num_pos;
        while (!mpi_can_sub(mpi_rem, mpi_num, mpi_tmp, mpi_dif)) mpi_tmp--;
      }
      mpi_subst(mpi_rem, mpi_num, mpi_tmp, mpi_dif);
      mpi_ans.MPI_VALUE[mpi_dif] += mpi_tmp;
      mpi_reform(mpi_rem);
    }
    if (!is_div) return mpi_rem;
    mpi_add_mul_reform(mpi_ans);
    return mpi_ans;
  }
  MPI operator/(const MPI &mpi_var) {
    bool b0 = MPI_SIGN, b1 = mpi_var.MPI_SIGN;
    if (!b0 && !b1) return mpi_abs_div(*this, mpi_var, true);
    if (b0 && b1) return mpi_abs_div(*this, mpi_var, true);
    MPI mpi_res = mpi_abs_div(*this, mpi_var, true);
    mpi_res.MPI_SIGN = !mpi_res.MPI_SIGN;
    return mpi_res;
  }
  MPI operator%(const MPI &mpi_var) {
    bool b0 = MPI_SIGN;
    if (!b0) return mpi_abs_div(*this, mpi_var, false);
    MPI mpi_res = mpi_abs_div(*this, mpi_var, false);
    mpi_res.MPI_SIGN = !mpi_res.MPI_SIGN;
    return mpi_res;
  }
  bool operator<(const MPI &mpi_var) const {
    bool b0 = MPI_SIGN, b1 = mpi_var.MPI_SIGN;
    if (!b0 && !b1) return mpi_abs_gt(*this, mpi_var);
    if (b0 && b1) return mpi_abs_sl(*this, mpi_var);
    if (((long long int)(this->MPI_VALUE).size()) == 1 &&
        ((long long int)(mpi_var.MPI_VALUE).size()) == 1) {
      if (this->MPI_VALUE.back() == 0 && mpi_var.MPI_VALUE.back() == 0)
        return true;
    }
    if (b0 && !b1) return true;
    if (!b0 && b1) return false;
  }
  bool operator>(const MPI &mpi_var) const {
    bool b0 = MPI_SIGN, b1 = mpi_var.MPI_SIGN;
    if (!b0 && !b1) return mpi_abs_sl(*this, mpi_var);
    if (b0 && b1) return mpi_abs_gt(*this, mpi_var);
    if (((long long int)(this->MPI_VALUE).size()) == 1 &&
        ((long long int)(mpi_var.MPI_VALUE).size()) == 1) {
      if (this->MPI_VALUE.back() == 0 && mpi_var.MPI_VALUE.back() == 0)
        return true;
    }
    if (b0 && !b1) return false;
    if (!b0 && b1) return true;
  }
  bool operator==(const MPI &mpi_var) const {
    bool b0 = MPI_SIGN, b1 = mpi_var.MPI_SIGN;
    if (b0 && b1) return mpi_abs_eq(*this, mpi_var);
    if (!b0 && !b1) return mpi_abs_eq(*this, mpi_var);
    if (((long long int)(this->MPI_VALUE).size()) == 1 &&
        ((long long int)(mpi_var.MPI_VALUE).size()) == 1) {
      if (this->MPI_VALUE.back() == 0 && mpi_var.MPI_VALUE.back() == 0)
        return true;
    }
    return false;
  }
  bool operator>=(const MPI &mpi_var) const { return !(*this < mpi_var); }
  bool operator<=(const MPI &mpi_var) const { return !(*this > mpi_var); }
  bool operator!=(const MPI &mpi_var) const { return !(*this == mpi_var); }
  void operator+=(const MPI &mpi_var) { *this = *this + mpi_var; }
  void operator-=(const MPI &mpi_var) { *this = *this - mpi_var; }
  void operator*=(const MPI &mpi_var) { *this = *this * mpi_var; }
  void operator/=(const MPI &mpi_var) { *this = *this / mpi_var; }
  void operator%=(const MPI &mpi_var) { *this = *this % mpi_var; }
  friend bool operator>(long long int mpi_li, const MPI &mpi_var) {
    return MPI(mpi_li) > mpi_var;
  }
  friend bool operator<(long long int mpi_li, const MPI &mpi_var) {
    return MPI(mpi_li) < mpi_var;
  }
  friend bool operator>=(long long int mpi_li, const MPI &mpi_var) {
    return MPI(mpi_li) >= mpi_var;
  }
  friend bool operator<=(long long int mpi_li, const MPI &mpi_var) {
    return MPI(mpi_li) <= mpi_var;
  }
  friend bool operator!=(long long int mpi_li, const MPI &mpi_var) {
    return MPI(mpi_li) != mpi_var;
  }
  friend bool operator==(long long int mpi_li, const MPI &mpi_var) {
    return MPI(mpi_li) == mpi_var;
  }
  MPI operator--() {
    *this = *this - MPI(1);
    return *this;
  }
  MPI operator++() {
    *this = *this + MPI(1);
    return *this;
  }
  MPI operator++(int mpi_i) {
    MPI mpi_res = *this;
    *this = *this + MPI(1);
    return mpi_res;
  }
  MPI operator--(int mpi_i) {
    MPI mpi_res = *this;
    *this = *this - MPI(1);
    return mpi_res;
  }
  MPI operator-() {
    MPI mpi_res = *this;
    mpi_res.MPI_SIGN = !mpi_res.MPI_SIGN;
    return mpi_res;
  }
  static bool mpi_abs_gt(const MPI &mpi0, const MPI &mpi1) {
    if (((long long int)(mpi0.MPI_VALUE).size()) ==
        ((long long int)(mpi1.MPI_VALUE).size())) {
      for (long long int i = ((long long int)(mpi0.MPI_VALUE).size()) - 1;
           0 <= i; i--) {
        if (mpi0.MPI_VALUE[i] != mpi1.MPI_VALUE[i]) {
          return mpi0.MPI_VALUE[i] < mpi1.MPI_VALUE[i];
        }
      }
    }
    return ((long long int)(mpi0.MPI_VALUE).size()) <
           ((long long int)(mpi1.MPI_VALUE).size());
  }
  static bool mpi_abs_sl(const MPI &mpi0, const MPI &mpi1) {
    if (((long long int)(mpi0.MPI_VALUE).size()) ==
        ((long long int)(mpi1.MPI_VALUE).size())) {
      for (long long int i = ((long long int)(mpi0.MPI_VALUE).size()) - 1;
           0 <= i; i--) {
        if (mpi0.MPI_VALUE[i] != mpi1.MPI_VALUE[i]) {
          return mpi0.MPI_VALUE[i] > mpi1.MPI_VALUE[i];
        }
      }
    }
    return ((long long int)(mpi0.MPI_VALUE).size()) >
           ((long long int)(mpi1.MPI_VALUE).size());
  }
  static bool mpi_abs_eq(const MPI &mpi0, const MPI &mpi1) {
    if (((long long int)(mpi0.MPI_VALUE).size()) !=
        ((long long int)(mpi1.MPI_VALUE).size()))
      return false;
    for (long long int i = 0;
         i < ((long long int)(((long long int)(mpi0.MPI_VALUE).size()))); i++) {
      if (mpi0.MPI_VALUE[i] != mpi1.MPI_VALUE[i]) return false;
    }
    return true;
  }

 private:
  static void mpi_reform_vec(vector<long long int> &mpi_vec) {
    if (((long long int)(mpi_vec).size()) == 0) mpi_vec.push_back(0);
    while (1 < ((long long int)(mpi_vec).size()) && mpi_vec.back() == 0)
      mpi_vec.pop_back();
  }
  static void mpi_add_mul_reform_vec(vector<long long int> &mpi_vec) {
    long long int carry = 0;
    for (long long int i = 0;
         i < ((long long int)(((long long int)(mpi_vec).size()))); i++) {
      mpi_vec[i] += carry;
      carry = mpi_vec[i] / 1000000;
      mpi_vec[i] %= 1000000;
    }
    mpi_vec.push_back(carry);
    mpi_reform_vec(mpi_vec);
  }
  static void mpi_reform(MPI &mpi_var) {
    mpi_reform_vec(mpi_var.MPI_VALUE);
    if (((long long int)(mpi_var.MPI_VALUE).size()) == 1 &&
        mpi_var.MPI_VALUE[0] == 0)
      mpi_var.MPI_SIGN = false;
  }
  static void mpi_add_mul_reform(MPI &mpi_var) {
    mpi_add_mul_reform_vec(mpi_var.MPI_VALUE);
    if (((long long int)(mpi_var.MPI_VALUE).size()) == 1 &&
        mpi_var.MPI_VALUE[0] == 0)
      mpi_var.MPI_SIGN = false;
  }
};
long long int n, k, RIGHT[600005], LEFT[600005],
    mini = (1ll << (long long int)(60));
vector<long long int> lucky;
long long int LEFT_SUM[600005], RIGHT_SUM[600005];
void make(long long int num) {
  if ((1000000005ll) * (1000000005ll) < num) return;
  lucky.push_back(num);
  make(num * 10 + 4);
  make(num * 10 + 7);
}
int main() {
  make(0);
  scanf("%I64d%I64d", &n, &k);
  lucky.push_back((1000000005ll) * (1000000005ll) * 2ll);
  sort(lucky.begin(), lucky.end());
  for (long long int i = 0; i < ((long long int)(n)); i++)
    scanf("%I64d%I64d", &LEFT[i], &RIGHT[i]);
  for (long long int i = 0; i < ((long long int)(n)); i++)
    mini = min(mini, RIGHT[i] - LEFT[i]);
  sort(LEFT, LEFT + n);
  sort(RIGHT, RIGHT + n);
  long long int cnt;
  cnt = 0;
  for (long long int i = 1; i < ((long long int)(lucky).size()); i++) {
    MPI sum = (lucky[i] - lucky[i - 1]);
    sum = sum * cnt;
    for (; cnt < n && RIGHT[cnt] <= lucky[i]; cnt++) {
      sum = sum + lucky[i] - RIGHT[cnt];
    }
    MPI INF = (1000000005ll) * (1000000005ll);
    RIGHT_SUM[i] = min(sum + RIGHT_SUM[i - 1], INF).to_long();
  }
  cnt = 0;
  for (long long int i = ((long long int)(lucky).size()) - 1; 0 < i; i--) {
    MPI sum = lucky[i + 1] - lucky[i];
    sum = sum * cnt;
    for (; cnt < n && lucky[i] <= LEFT[n - 1 - cnt]; cnt++) {
      sum += LEFT[n - 1 - cnt] - lucky[i];
    }
    MPI INF = (1000000005ll) * (1000000005ll);
    LEFT_SUM[i] = min(sum + LEFT_SUM[i + 1], INF).to_long();
  }
  long long int res = 0;
  for (long long int i = 1; i < ((long long int)(lucky).size()); i++) {
    if (k < LEFT_SUM[i] + RIGHT_SUM[i]) continue;
    long long int low0 = i, high0 = ((long long int)(lucky).size()) - 1;
    while (low0 + 1 < high0) {
      long long int mid = (low0 + high0) / 2;
      if (LEFT_SUM[i] + RIGHT_SUM[mid] <= k)
        low0 = mid;
      else
        high0 = mid;
    }
    long long int low1 = i, high1 = ((long long int)(lucky).size()) - 1;
    while (low1 + 1 < high1) {
      long long int mid = (low1 + high1) / 2;
      if (lucky[mid] - lucky[i] <= mini)
        low1 = mid;
      else
        high1 = mid;
    }
    res = max(res, min(low0 - i + 1, low1 - i + 1));
  }
  cout << res << endl;
}
