#include <bits/stdc++.h>
using namespace std;
void form(string s) {
  int len = s.size();
  if (len % 2 == 1) {
    len++;
  }
  for (int i = 0; i < len / 2; i++) printf("4");
  for (int j = 0; j < len / 2; j++) printf("7");
  printf("\n");
  exit(0);
}
string converttolucky(string s) {
  int flag = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '4' || s[i] == '7') {
      continue;
    } else {
      if (s[i] < '4') {
        s[i] = '4';
        for (int j = i + 1; j < s.size(); j++) s[j] = '4';
        return s;
      } else if (s[i] < '7') {
        s[i] = '7';
        for (int j = i + 1; j < s.size(); j++) s[j] = '4';
        return s;
      } else {
        flag = 0;
        for (int k = i - 1; k >= 0; k--) {
          if (s[k] == '4') {
            flag = 1;
            s[k] = '7';
            for (int j = k + 1; j < s.size(); j++) {
              s[j] = '4';
            }
            return s;
          }
        }
        if (flag == 0) {
          s.append("4");
          form(s);
        }
      }
    }
  }
  return s;
}
string more4(string s) {
  int len4 = 0;
  int len7 = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '4')
      len4++;
    else
      len7++;
  }
  if (len4 >= len7) return s;
  int flag = 0;
  int rem4 = 0;
  int rem7 = 0;
  for (int j = s.size() - 1; j >= 0; j--) {
    if (s[j] == '4') {
      int tmp7 = len7 - rem7 + 1;
      rem4++;
      int tmp4 = len4 - rem4;
      if (tmp4 + (s.size() - j - 1) >= tmp7) {
        s[j] = '7';
        for (int k = j + 1; k < s.size(); k++) s[k] = '4';
        return s;
      }
    } else
      rem7++;
  }
  s.append("4");
  form(s);
}
string solve(string s) {
  int len4 = 0;
  int len7 = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '4')
      len4++;
    else
      len7++;
  }
  for (int j = s.size() - 1; j >= 0; j--) {
    if (len4 == len7) {
      cout << s << "\n";
      return s;
    }
    if (s[j] == '4') {
      s[j] = '7';
      len4--;
      len7++;
    }
  }
  assert(len4 == len7);
}
int main() {
  string s;
  cin >> s;
  int len = s.size();
  if (len % 2 == 1) form(s);
  s = converttolucky(s);
  s = more4(s);
  solve(s);
}
