#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 27;
const double EPS = 1e-10;
const double PI = 3.1415926535897932384626433832795;
const int CLK = CLOCKS_PER_SEC;
string ans;
string number;
int n;
void solve(int cnt, int f, int s, bool ok) {
  if (cnt == 0) {
    for (int i = 0; i < n; i++) cout << ans[i];
    cout << endl;
    exit(0);
  }
  if (f > 0 && (number[n - cnt] <= '4' || ok)) {
    ans[n - cnt] = '4';
    solve(cnt - 1, f - 1, s, ok || (number[n - cnt] < '4'));
  }
  if (s > 0 && (number[n - cnt] <= '7' || ok)) {
    ans[n - cnt] = '7';
    solve(cnt - 1, f, s - 1, ok || (number[n - cnt] < '7'));
  }
}
void doit(int l) {
  if (l % 2 == 1) return;
  if (l > n) {
    for (int i = 0; i < l / 2; i++) cout << 4;
    for (int i = 0; i < l / 2; i++) cout << 7;
    cout << endl;
    exit(0);
  }
  solve(n, n / 2, n / 2, false);
}
int main() {
  cin >> number;
  n = number.size();
  ans = string(n + 2, ' ');
  doit(n);
  doit(n + 1);
  doit(n + 2);
  return 0;
}
