#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T checkmin(T &a, T b) {
  return (a < b) ? a : a = b;
}
template <class T>
inline T checkmax(T &a, T b) {
  return (a > b) ? a : a = b;
}
template <class T>
T GCD(T a, T b) {
  if (a < 0) return GCD(-a, b);
  if (b < 0) return GCD(a, -b);
  return (a == 0) ? b : GCD(b % a, a);
}
template <class T>
T LCM(T a, T b) {
  if (a < 0) return LCM(-a, b);
  if (b < 0) return LCM(a, -b);
  return (a == 0 || b == 0) ? 0 : a / GCD(a, b) * b;
}
namespace Poor {
int A, L, Ans;
map<int, vector<int> > Mapping;
int Count(unsigned int n) {
  if (n < 10) return (n == 4 || n == 7);
  return Count(n / 10) + Count(n % 10);
}
inline bool Check(unsigned int X, unsigned int Y, int L) {
  for (int i = 0; i < 100; ++i) {
    int l = rand() % L;
    if (Count(X + l) != Count(Y + l)) return 0;
    if (i < L && Count(X + i) != Count(Y + i)) return 0;
    if (i < L && Count(X + L - i - 1) != Count(Y + L - i - 1)) return 0;
    if ((long long)i * 99 < L && Count(X + i * 99) != Count(Y + i * 99))
      return 0;
    if ((long long)i * 9999 < L && Count(X + i * 9999) != Count(Y + i * 9999))
      return 0;
    if ((long long)i * 999999 < L &&
        Count(X + i * 999999) != Count(Y + i * 999999))
      return 0;
    if ((long long)i * 99999999 < L &&
        Count(X + i * 99999999) != Count(Y + i * 99999999))
      return 0;
  }
  return 1;
}
bool Tried(int X, int Y, int pw) {
  int Tmp = Count(X) - Count(Y);
  for (int i = 1; i < L && X + i < pw && Y + i < pw; ++i)
    if (Count(X + i) - Count(Y + i) != Tmp) return 0;
  int Start = min(pw - X, pw - Y);
  if (Start >= L) return 1;
  Tmp = Count(X + Start) - Count(Y + Start);
  for (int i = Start + 1; i < L && (X + i < pw || Y + i < pw); ++i)
    if (Count(X + i) - Count(Y + i) != Tmp) return 0;
  Start = max(pw - X, pw - Y);
  Tmp = Count(X + Start) - Count(Y + Start);
  for (int i = Start + 1; i < L && X + i < pw * 2 && Y + i < pw * 2; ++i)
    if (Count(X + i) - Count(Y + i) != Tmp) return 0;
  return 1;
}
int Log(int first) {
  int res = 0;
  while (first > 1) {
    first /= 10;
    ++res;
  }
  return res;
}
void DFS(int v, int c, int pw) {
  if (v < Ans) {
    if (c == 0) {
      if (A < v && Check(A, v, L)) Ans = v;
      if (pw == 1000000000 && A < v + pw && v + pw < Ans && Check(A, v + pw, L))
        Ans = v + pw;
    }
    if (pw == 1000000000) return;
    if (Log(1000000000 / pw) < c) return;
    if ((pw <= 1000 || L < 1000000000 / pw) && !Tried(A % pw, v, pw)) return;
    if (c > 0) {
      DFS(v + pw * 4, c - 1, pw * 10);
      DFS(v + pw * 7, c - 1, pw * 10);
    }
    for (int i = 0; i < 10; ++i)
      if (i != 4 && i != 7) DFS(v + pw * i, c, pw * 10);
  }
}
void AnotherWay() {
  Mapping.clear();
  for (int i = 0; i < 200001; ++i) Mapping[Count(i)].push_back(i);
  for (int i = 0; i < 10000; ++i)
    if (Tried(i, A % 10000, 10000)) {
      int a = Count(A) - Count(i);
      int b = Count(A + L - 1) - Count(i + L - 1);
      if (a < 0 || b < 0) continue;
      vector<int>::iterator ita, itb;
      ita = lower_bound(Mapping[a].begin(), Mapping[a].end(), A / 10000);
      itb = lower_bound(Mapping[b].begin(), Mapping[b].end(),
                        (A + L - 1) / 10000);
      int j = (i + L - 1) % 10000;
      int t = 0;
      while (ita != Mapping[a].end() && itb != Mapping[b].end() && t < 1000) {
        ++t;
        if (*ita * 10000 + i >= Ans) break;
        if (*ita * 10000 + i <= A) ++ita;
        if (*ita * 10000 + i + L - 1 < *itb * 10000 + j) {
          if (*itb - *ita < 50)
            ++ita;
          else
            ita = lower_bound(Mapping[a].begin(), Mapping[a].end(),
                              (*itb * 10000 + j - L + 1) / 10000);
        }
        if (*ita * 10000 + i + L - 1 > *itb * 10000 + j) {
          if (*ita - *itb < 50)
            ++itb;
          else
            itb = lower_bound(Mapping[b].begin(), Mapping[b].end(),
                              (*ita * 10000 + i + L - 1) / 10000);
        }
        if (*ita * 10000 + i + L - 1 == *itb * 10000 + j) {
          if (*ita * 10000 + i < Ans && Check(*ita * 10000 + i, A, L)) {
            Ans = *ita * 10000 + i;
            break;
          }
          ++ita;
          ++itb;
        }
      }
    }
}
void Run() {
  srand(time(NULL));
  cin >> A >> L;
  Ans = A + 1000000000;
  if (L <= 10) {
    AnotherWay();
    cout << Ans << endl;
    return;
  }
  int c = Count(A);
  if (c > 0) {
    DFS(4, c - 1, 10);
    DFS(7, c - 1, 10);
  }
  for (int i = 0; i < 10; ++i)
    if (i != 4 && i != 7) DFS(i, c, 10);
  cout << Ans << endl;
}
}  // namespace Poor
int main() { Poor::Run(); }

### Prompt

Develop a solution in Cpp to the problem described below:

Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.

One day Petya came across an interval of numbers [a, a + l - 1]. Let F(x) be the number of lucky digits of number x. Find the minimum b (a < b) such, that F(a) = F(b), F(a + 1) = F(b + 1), ..., F(a + l - 1) = F(b + l - 1).

Input

The single line contains two integers a and l (1 ≤ a, l ≤ 109) — the interval's first number and the interval's length correspondingly.

Output

On the single line print number b — the answer to the problem.

Examples

Input

7 4


Output

17


Input

4 7


Output

14

Note

Consider that [a, b] denotes an interval of integers; this interval includes the boundaries. That is, <image>

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T checkmin(T &a, T b) {
  return (a < b) ? a : a = b;
}
template <class T>
inline T checkmax(T &a, T b) {
  return (a > b) ? a : a = b;
}
template <class T>
T GCD(T a, T b) {
  if (a < 0) return GCD(-a, b);
  if (b < 0) return GCD(a, -b);
  return (a == 0) ? b : GCD(b % a, a);
}
template <class T>
T LCM(T a, T b) {
  if (a < 0) return LCM(-a, b);
  if (b < 0) return LCM(a, -b);
  return (a == 0 || b == 0) ? 0 : a / GCD(a, b) * b;
}
namespace Poor {
int A, L, Ans;
map<int, vector<int> > Mapping;
int Count(unsigned int n) {
  if (n < 10) return (n == 4 || n == 7);
  return Count(n / 10) + Count(n % 10);
}
inline bool Check(unsigned int X, unsigned int Y, int L) {
  for (int i = 0; i < 100; ++i) {
    int l = rand() % L;
    if (Count(X + l) != Count(Y + l)) return 0;
    if (i < L && Count(X + i) != Count(Y + i)) return 0;
    if (i < L && Count(X + L - i - 1) != Count(Y + L - i - 1)) return 0;
    if ((long long)i * 99 < L && Count(X + i * 99) != Count(Y + i * 99))
      return 0;
    if ((long long)i * 9999 < L && Count(X + i * 9999) != Count(Y + i * 9999))
      return 0;
    if ((long long)i * 999999 < L &&
        Count(X + i * 999999) != Count(Y + i * 999999))
      return 0;
    if ((long long)i * 99999999 < L &&
        Count(X + i * 99999999) != Count(Y + i * 99999999))
      return 0;
  }
  return 1;
}
bool Tried(int X, int Y, int pw) {
  int Tmp = Count(X) - Count(Y);
  for (int i = 1; i < L && X + i < pw && Y + i < pw; ++i)
    if (Count(X + i) - Count(Y + i) != Tmp) return 0;
  int Start = min(pw - X, pw - Y);
  if (Start >= L) return 1;
  Tmp = Count(X + Start) - Count(Y + Start);
  for (int i = Start + 1; i < L && (X + i < pw || Y + i < pw); ++i)
    if (Count(X + i) - Count(Y + i) != Tmp) return 0;
  Start = max(pw - X, pw - Y);
  Tmp = Count(X + Start) - Count(Y + Start);
  for (int i = Start + 1; i < L && X + i < pw * 2 && Y + i < pw * 2; ++i)
    if (Count(X + i) - Count(Y + i) != Tmp) return 0;
  return 1;
}
int Log(int first) {
  int res = 0;
  while (first > 1) {
    first /= 10;
    ++res;
  }
  return res;
}
void DFS(int v, int c, int pw) {
  if (v < Ans) {
    if (c == 0) {
      if (A < v && Check(A, v, L)) Ans = v;
      if (pw == 1000000000 && A < v + pw && v + pw < Ans && Check(A, v + pw, L))
        Ans = v + pw;
    }
    if (pw == 1000000000) return;
    if (Log(1000000000 / pw) < c) return;
    if ((pw <= 1000 || L < 1000000000 / pw) && !Tried(A % pw, v, pw)) return;
    if (c > 0) {
      DFS(v + pw * 4, c - 1, pw * 10);
      DFS(v + pw * 7, c - 1, pw * 10);
    }
    for (int i = 0; i < 10; ++i)
      if (i != 4 && i != 7) DFS(v + pw * i, c, pw * 10);
  }
}
void AnotherWay() {
  Mapping.clear();
  for (int i = 0; i < 200001; ++i) Mapping[Count(i)].push_back(i);
  for (int i = 0; i < 10000; ++i)
    if (Tried(i, A % 10000, 10000)) {
      int a = Count(A) - Count(i);
      int b = Count(A + L - 1) - Count(i + L - 1);
      if (a < 0 || b < 0) continue;
      vector<int>::iterator ita, itb;
      ita = lower_bound(Mapping[a].begin(), Mapping[a].end(), A / 10000);
      itb = lower_bound(Mapping[b].begin(), Mapping[b].end(),
                        (A + L - 1) / 10000);
      int j = (i + L - 1) % 10000;
      int t = 0;
      while (ita != Mapping[a].end() && itb != Mapping[b].end() && t < 1000) {
        ++t;
        if (*ita * 10000 + i >= Ans) break;
        if (*ita * 10000 + i <= A) ++ita;
        if (*ita * 10000 + i + L - 1 < *itb * 10000 + j) {
          if (*itb - *ita < 50)
            ++ita;
          else
            ita = lower_bound(Mapping[a].begin(), Mapping[a].end(),
                              (*itb * 10000 + j - L + 1) / 10000);
        }
        if (*ita * 10000 + i + L - 1 > *itb * 10000 + j) {
          if (*ita - *itb < 50)
            ++itb;
          else
            itb = lower_bound(Mapping[b].begin(), Mapping[b].end(),
                              (*ita * 10000 + i + L - 1) / 10000);
        }
        if (*ita * 10000 + i + L - 1 == *itb * 10000 + j) {
          if (*ita * 10000 + i < Ans && Check(*ita * 10000 + i, A, L)) {
            Ans = *ita * 10000 + i;
            break;
          }
          ++ita;
          ++itb;
        }
      }
    }
}
void Run() {
  srand(time(NULL));
  cin >> A >> L;
  Ans = A + 1000000000;
  if (L <= 10) {
    AnotherWay();
    cout << Ans << endl;
    return;
  }
  int c = Count(A);
  if (c > 0) {
    DFS(4, c - 1, 10);
    DFS(7, c - 1, 10);
  }
  for (int i = 0; i < 10; ++i)
    if (i != 4 && i != 7) DFS(i, c, 10);
  cout << Ans << endl;
}
}  // namespace Poor
int main() { Poor::Run(); }

```