#include <bits/stdc++.h>
using namespace std;
long long max(long long a, long long b) {
  if (a > b)
    return a;
  else
    return b;
}
long long min(long long a, long long b) {
  if (a < b)
    return a;
  else
    return b;
}
long long mod = 1000000007;
string s;
int n;
map<int, int> f;
int calc(int i, char ans[]) {
  if (i == n) return f[4] == f[7];
  for (auto it : f) {
    int x = s[i] - '0';
    if (it.second > 0 and it.first >= x) {
      f[it.first]--;
      ans[i] = (it.first + '0');
      if (it.first > x) {
        int y = (n - i - 1 - abs(f[7] - f[4]));
        if (y % 2 == 0) {
          string s1;
          if (f[4] > f[7])
            s1 = string((f[4] - f[7] + y / 2), '4') + string(y / 2, '7');
          else
            s1 = string(y / 2, '4') + string((f[7] - f[4] + y / 2), '7');
          int k = 0;
          for (int j = i + 1; j < n; j++) {
            ans[j] = s1[k];
            k++;
          }
          return 1;
        }
      }
      if (calc(i + 1, ans)) return 1;
      f[it.first]++;
    }
  }
  return 0;
}
bool test = 0;
void solve() {
  cin >> s;
  n = s.size();
  if (n & 1) {
    int x = (n + 1) / 2;
    cout << string(x, '4') + string(x, '7');
    return;
  }
  f[4] = n / 2;
  f[7] = n / 2;
  char ans[n];
  if (calc(0, ans)) {
    for (int i = 0; i < n; i++) cout << ans[i];
  } else
    cout << string(n / 2 + 1, '4') + string(n / 2 + 1, '7');
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  if (test) cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
