#include <bits/stdc++.h>
using namespace std;
string build(int x, int y) {
  string ans;
  for (int n_ = (x), i = 0; i < n_; ++i) ans += '4';
  for (int n_ = (y), i = 0; i < n_; ++i) ans += '7';
  return ans;
}
string solve(string number) {
  string ans;
  if (((int)(number).size()) % 2 == 1) {
    int sz = ((int)(number).size()) + 1;
    return build(sz / 2, sz / 2);
  } else {
    int cnt4 = count((number).begin(), (number).end(), '4');
    int cnt7 = count((number).begin(), (number).end(), '7');
    if (cnt4 == cnt7 && cnt4 + cnt7 == ((int)(number).size())) {
      return number;
    }
    int should_change = ((int)(number).size()) - 1;
    for (int n_ = (((int)(number).size())), i = 0; i < n_; ++i) {
      if (number[i] != '4' && number[i] != '7') {
        should_change = i;
        break;
      }
    }
    cnt4 = cnt7 = 0;
    for (int n_ = (should_change + 1), i = 0; i < n_; ++i) {
      if (number[i] == '4') cnt4++;
      if (number[i] == '7') cnt7++;
    }
    int sz = number.size() / 2;
    for (int i = should_change; i >= 0; --i) {
      if (number[i] == '4') cnt4--;
      if (number[i] == '7') cnt7--;
      if ('4' > number[i]) {
        if (cnt4 + 1 <= sz && cnt7 <= sz) {
          return number.substr(0, i) + "4" + build(sz - cnt4 - 1, sz - cnt7);
        }
      }
      if ('7' > number[i]) {
        if (cnt4 <= sz && cnt7 + 1 <= sz) {
          return number.substr(0, i) + "7" + build(sz - cnt4, sz - cnt7 - 1);
        }
      }
    }
    int n = sz * 2 + 2;
    return build(n / 2, n / 2);
  }
}
int main() {
  string number;
  while (cin >> number) {
    cout << solve(number) << endl;
  }
  return 0;
}
