#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
string s;
void answer(string ans) {
  if (ans < s || ans.size() % 2) {
    int n = ((s.size()) / 2) + 1;
    ans = string(n, '4') + string(n, '7');
  }
  cout << ans << '\n';
  exit(0);
}
int main() {
  cin >> s;
  int n = s.size();
  s[n - 1]--;
  for (int i = n - 1; i >= 0; --i)
    if (s[i] < '0') {
      s[i] += 10;
      s[i - 1]--;
    }
  int four_rem = n / 2, seven_rem = n - four_rem;
  string ans;
  int last_kill = -1;
  for (int i = 0; i < n; ++i) {
    if (s[i] < '4' && four_rem > 0) {
      ans += '4';
      --four_rem;
      for (int j = i + 1; j < n; ++j)
        if (four_rem) {
          ans += '4';
          --four_rem;
        } else {
          ans += '7';
          --seven_rem;
        }
      answer(ans);
    }
    if (s[i] < '7' && seven_rem > 0) {
      last_kill = i;
    }
    if (s[i] == '4') {
      if (four_rem == 0) break;
      --four_rem;
      ans += '4';
    } else if (s[i] == '7') {
      if (seven_rem == 0) break;
      --seven_rem;
      ans += '7';
    } else {
      break;
    }
  }
  if (last_kill == -1) answer("");
  while (four_rem-- > 0) ans += '4';
  while (seven_rem-- > 0) ans += '7';
  for (int i = last_kill; i < n; ++i)
    if (ans[i] == '7') {
      swap(ans[i], ans[last_kill]);
      break;
    }
  sort(ans.begin() + last_kill + 1, ans.end());
  answer(ans);
}
