#include <bits/stdc++.h>
using namespace std;
int lucky(long long x) {
  int ans = 0;
  while (x > 0) {
    if (x % 10 == 4 || x % 10 == 7) ans++;
    x /= 10;
  }
  return ans;
}
map<pair<long long, int>, int> mp1;
long long func1(long long low, int x) {
  int i;
  long long ans = (1ll << 40);
  if (x < 0) return (1ll << 40);
  pair<long long, int> st = make_pair(low, x);
  if (mp1.find(st) != mp1.end()) return mp1[st];
  if (low <= 3) {
    if (x == 0) return low;
    ans = 0;
    for ((i) = 0; (i) < (int)(x); (i)++) ans = ans * 10 + 4;
    return mp1[st] = ans;
  }
  for ((i) = 0; (i) < (int)(10); (i)++) {
    if (i < low % 10) {
      long long tmp = func1(low / 10 + 1, x - lucky(i));
      ans = min(ans, tmp * 10 + i);
    } else {
      long long tmp = func1(low / 10, x - lucky(i));
      ans = min(ans, tmp * 10 + i);
    }
  }
  return mp1[st] = ans;
}
long long func2(long long low, int x, int y) {
  int i;
  long long ans = (1ll << 40);
  if (x < 0 || y < 0) return (1ll << 40);
  for ((i) = 0; (i) < (int)(9); (i)++)
    if (y - x == lucky(i + 1) - lucky(i)) {
      if (i < low % 10) {
        long long tmp = func1(low / 10 + 1, x - lucky(i));
        ans = min(ans, tmp * 10 + i);
      } else {
        long long tmp = func1(low / 10, x - lucky(i));
        ans = min(ans, tmp * 10 + i);
      }
    }
  return ans;
}
long long func3(long long low, int x, int y) {
  long long ans = (1ll << 40);
  int i;
  for (i = 0;; i++) {
    long long tmp = func2(low, x, y);
    int j;
    for ((j) = 0; (j) < (int)(i); (j)++) tmp = min(tmp * 10 + 9, (1ll << 40));
    ans = min(ans, tmp);
    if (low == 0) return ans;
    low /= 10;
  }
}
long long func(long long low, long long high) {
  if (high / 10 - low / 10 >= 2) {
    long long tmp = func(low / 10, high / 10);
    return tmp * 10 + low % 10;
  }
  long long ans = (1ll << 40);
  int i, j, k;
  for ((i) = 0; (i) < (int)(10); (i)++) {
    j = i + (int)(high - low);
    if (j >= 20) continue;
    int x = lucky(low) - lucky(i);
    int y = 0;
    if (j >= 10) y = lucky(high) - lucky(j - 10);
    bool failed = false;
    for (k = i; k <= j; k++) {
      int tmp1 = lucky(low + k - i);
      int tmp2 = ((k >= 10) ? (y + lucky(k - 10)) : (x + lucky(k)));
      if (tmp1 != tmp2) {
        failed = true;
        break;
      }
    }
    if (failed) continue;
    long long small = (low - i + 10) / 10;
    if (j >= 10) {
      long long tmp = func3(small, x, y);
      ans = min(ans, tmp * 10 + i);
    } else {
      long long tmp = func1(small, x);
      ans = min(ans, tmp * 10 + i);
    }
  }
  return ans;
}
int main(void) {
  long long a, d;
  cin >> a >> d;
  long long ans = func(a, a + d - 1);
  cout << ans << endl;
  return 0;
}

### 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;
int lucky(long long x) {
  int ans = 0;
  while (x > 0) {
    if (x % 10 == 4 || x % 10 == 7) ans++;
    x /= 10;
  }
  return ans;
}
map<pair<long long, int>, int> mp1;
long long func1(long long low, int x) {
  int i;
  long long ans = (1ll << 40);
  if (x < 0) return (1ll << 40);
  pair<long long, int> st = make_pair(low, x);
  if (mp1.find(st) != mp1.end()) return mp1[st];
  if (low <= 3) {
    if (x == 0) return low;
    ans = 0;
    for ((i) = 0; (i) < (int)(x); (i)++) ans = ans * 10 + 4;
    return mp1[st] = ans;
  }
  for ((i) = 0; (i) < (int)(10); (i)++) {
    if (i < low % 10) {
      long long tmp = func1(low / 10 + 1, x - lucky(i));
      ans = min(ans, tmp * 10 + i);
    } else {
      long long tmp = func1(low / 10, x - lucky(i));
      ans = min(ans, tmp * 10 + i);
    }
  }
  return mp1[st] = ans;
}
long long func2(long long low, int x, int y) {
  int i;
  long long ans = (1ll << 40);
  if (x < 0 || y < 0) return (1ll << 40);
  for ((i) = 0; (i) < (int)(9); (i)++)
    if (y - x == lucky(i + 1) - lucky(i)) {
      if (i < low % 10) {
        long long tmp = func1(low / 10 + 1, x - lucky(i));
        ans = min(ans, tmp * 10 + i);
      } else {
        long long tmp = func1(low / 10, x - lucky(i));
        ans = min(ans, tmp * 10 + i);
      }
    }
  return ans;
}
long long func3(long long low, int x, int y) {
  long long ans = (1ll << 40);
  int i;
  for (i = 0;; i++) {
    long long tmp = func2(low, x, y);
    int j;
    for ((j) = 0; (j) < (int)(i); (j)++) tmp = min(tmp * 10 + 9, (1ll << 40));
    ans = min(ans, tmp);
    if (low == 0) return ans;
    low /= 10;
  }
}
long long func(long long low, long long high) {
  if (high / 10 - low / 10 >= 2) {
    long long tmp = func(low / 10, high / 10);
    return tmp * 10 + low % 10;
  }
  long long ans = (1ll << 40);
  int i, j, k;
  for ((i) = 0; (i) < (int)(10); (i)++) {
    j = i + (int)(high - low);
    if (j >= 20) continue;
    int x = lucky(low) - lucky(i);
    int y = 0;
    if (j >= 10) y = lucky(high) - lucky(j - 10);
    bool failed = false;
    for (k = i; k <= j; k++) {
      int tmp1 = lucky(low + k - i);
      int tmp2 = ((k >= 10) ? (y + lucky(k - 10)) : (x + lucky(k)));
      if (tmp1 != tmp2) {
        failed = true;
        break;
      }
    }
    if (failed) continue;
    long long small = (low - i + 10) / 10;
    if (j >= 10) {
      long long tmp = func3(small, x, y);
      ans = min(ans, tmp * 10 + i);
    } else {
      long long tmp = func1(small, x);
      ans = min(ans, tmp * 10 + i);
    }
  }
  return ans;
}
int main(void) {
  long long a, d;
  cin >> a >> d;
  long long ans = func(a, a + d - 1);
  cout << ans << endl;
  return 0;
}

```