#include <bits/stdc++.h>
using namespace std;
const int ml = 100005;
string n;
int len, len2;
bool go1() {
  for (int i = 0; i < len2; i++) {
    if (n[i] < '7') return 1;
    if (n[i] > '7') return 0;
  }
  for (int i = len2; i < len; i++) {
    if (n[i] < '4') return 1;
    if (n[i] > '4') return 0;
  }
  return 1;
}
int main() {
  cin >> n;
  len = n.size();
  if (len & 1) {
    n = "1";
    for (int i = 0; i < len; i++) n.push_back('0');
    len++;
  }
  len2 = len / 2;
  if (!go1()) {
    len += 2;
    len2 += 1;
    n = "1";
    for (int i = 0; i < len - 1; i++) n.push_back('0');
  }
  int rem4 = len2, rem7 = len2;
  bool lesser = 0;
  string ans;
  for (int i = 0; i < len; i++) ans.push_back('7');
  for (int i = 0; i < len; i++) {
    if (lesser) {
      if (rem4)
        ans[i] = '4', rem4--;
      else
        ans[i] = '7', rem7--;
    } else {
      if (n[i] <= '4' && rem4) {
        ans[i] = '4', rem4--;
        if (n[i] < '4') lesser = 1;
      } else if (n[i] <= '7' && rem7) {
        ans[i] = '7', rem7--;
        if (n[i] < '7') lesser = 1;
      } else {
        int j;
        for (j = i - 1; j >= 0; j--) {
          if (ans[j] != '4')
            rem7++;
          else {
            if (rem7 > 0)
              break;
            else
              rem4++;
          }
        }
        ans[j] = '7';
        lesser = 1;
        rem4++;
        rem7--;
        i = j;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
