#include <bits/stdc++.h>
using namespace std;
string num;
int len;
string big, sma;
bool bigThan(string a, string b) {
  if (a.size() > b.size())
    return true;
  else if (a.size() < b.size())
    return false;
  else {
    for (int i = 0; i < a.size(); ++i)
      if (((int)a[i] - (int)b[i]) > 0)
        return true;
      else if (((int)a[i] < (int)b[i]))
        return false;
  }
  return false;
}
int main() {
  cin >> num;
  len = num.size() % 2 == 0 ? num.size() : num.size() + 1;
  for (int i = 0; i < len / 2; ++i) {
    big += '7';
    sma += '4';
  }
  for (int i = 0; i < len / 2; ++i) {
    big += '4';
    sma += '7';
  }
  if (bigThan(num, big)) {
    cout << '4' << sma << '7' << endl;
  } else if (bigThan(sma, num)) {
    cout << sma << endl;
  } else {
    int index = -1;
    char tar = '7';
    for (int i = 0; i < num.size(); ++i) {
      if (num[i] != '4' && num[i] != '7') {
        index = i;
        tar = num[i];
        break;
      }
    }
    if (tar == '7') {
    } else if (tar > '7') {
      for (int i = index - 1; i >= 0; --i) {
        if (num[i] == '7') {
          num[i] = '4';
        } else if (num[i] == '4') {
          num[i] = '7';
          break;
        }
      }
      for (int i = index; i < num.size(); ++i) {
        num[i] = '4';
      }
    } else if (tar > '4') {
      num[index] = '7';
      for (int i = index + 1; i < num.size(); ++i) num[i] = '4';
    } else {
      for (int i = index; i < num.size(); ++i) num[i] = '4';
    }
    int c7 = 0, c4 = 0;
    for (int i = 0; i < num.size(); ++i) {
      if (num[i] == '7')
        ++c7;
      else if (num[i] == '4')
        ++c4;
    }
    if (c4 < c7) {
      for (int i = num.size() - 1; i >= 0; --i) {
        if (num[i] != '4') {
          num[i] = '4';
          c4++;
          c7--;
          if (c4 == c7) break;
        }
      }
      for (int i = num.size() - 1; i >= 0; --i) {
        if (num[i] == '7' && num[i - 1] == '4') {
          num[i] = '4';
          num[i - 1] = '7';
          for (int j = i + 1; j < num.size(); ++j) {
            if (num[j] != '4') {
              num[j] = '4';
              c4++;
              c7--;
            }
          }
          break;
        }
      }
    }
    if (c4 > c7)
      for (int i = num.size() - 1; i >= 0; --i) {
        if (num[i] != '7') {
          num[i] = '7';
          c4--;
          c7++;
          if (c4 == c7) break;
        }
      }
    cout << num << endl;
  }
}
