Problem: Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.

Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. For example, numbers 47, 7744, 474477 are super lucky and 4, 744, 467 are not.

One day Petya came across a positive integer n. Help him to find the least super lucky number which is not less than n.

Input

The only line contains a positive integer n (1 ≤ n ≤ 10100000). This number doesn't have leading zeroes.

Output

Output the least super lucky number that is more than or equal to n.

Examples

Input

4500


Output

4747


Input

47


Output

47

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename T1>
T amax(T &a, T1 b) {
  if (b > a) a = b;
  return a;
}
template <typename T, typename T1>
T amin(T &a, T1 b) {
  if (b < a) a = b;
  return a;
}
bool isPrime(long long x) {
  if (x == 1) return false;
  for (long long i = 2; i * i <= x; i++) {
    if (x % i == 0) {
      return false;
    }
  }
  return true;
}
bool isPowerOfTwo(long long n) {
  if (n == 0) return false;
  return (ceil(log2(n)) == floor(log2(n)));
}
long long gcdByBit(long long a, long long b) {
  if (!a || !b) return a | b;
  unsigned shift = __builtin_ctz(a | b);
  a >>= __builtin_ctzl(a);
  do {
    b >>= __builtin_ctzl(b);
    if (a > b) {
      swap(a, b);
    }
    b -= a;
  } while (b);
  return a << shift;
}
long long powerMod(long long n, long long p) {
  long long res = 1;
  while (p) {
    if (p % 2 == 0) {
      n = n * 1ll * n % 1000000007;
      p /= 2;
    } else {
      res = res * 1ll * n % 1000000007;
      p--;
    }
  }
  return res;
}
long long powerMod2(long long b, long long p, long long m) {
  if (p == 0) return 1;
  return (b * powerMod2(b, p - 1, m) % m) % m;
}
long long fact(long long n) {
  long long res = 1;
  for (long long i = 1; i <= n; i++) {
    res = res * 1ll * i % 1000000007;
  }
  return res;
}
long long nCr(long long n, long long r) {
  return fact(n) * 1ll * powerMod(fact(r), 1000000007 - 2) % 1000000007 * 1ll *
         powerMod(fact(n - r), 1000000007 - 2) % 1000000007;
}
pair<string, string> make(long long n) {
  string small = "", lar = "";
  for (long long i = 0; i < n; i++) {
    small += '4';
    lar += '7';
  }
  for (long long i = 0; i < n; i++) {
    small += '7';
    lar += '4';
  }
  return make_pair(small, lar);
}
void ans() {
  string s;
  cin >> s;
  long long c1 = 0, c2 = 0;
  bool f = 0;
  for (long long i = 0; i < s.length(); i++) {
    if (s[i] == '7')
      c1++;
    else if (s[i] == '4')
      c2++;
    else {
      f = 1;
      break;
    }
  }
  if (!f && c1 == c2) {
    cout << s << '\n';
    return;
  }
  long long n = (long long)ceil((double)s.length() / 2.0);
  pair<string, string> p = make(n);
  if (s.length() % 2 != 0) {
    cout << p.first << '\n';
    return;
  }
  if (s > p.second) {
    cout << make(n + 1).first;
    return;
  }
  while (p.first < s) {
    next_permutation(p.first.begin(), p.first.end());
  }
  cout << p.first << '\n';
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long tc = 1;
  while (tc--) {
    ans();
  }
  return 0;
}