#include <bits/stdc++.h>
using namespace std;
string a;
string ans = "", x = "";
bool Judge() {
  if (a.size() % 2) {
    return false;
  }
  string temp = "";
  for (int i = 0; i < a.size(); i++) {
    if (i < a.size() / 2) {
      temp += "7";
    } else {
      temp += "4";
    }
  }
  return temp >= a;
}
void Deal() {
  int t = a.size();
  t = t % 2 ? t + 1 : t + 2;
  for (int i = 0; i < t; i++) {
    if (i < t / 2) {
      ans += "4";
    } else {
      ans += "7";
    }
  }
  return;
}
void Dfs(int num4, int num7, int pos, bool flag) {
  if (ans != "") {
    return;
  }
  if (x < a.substr(0, x.size())) {
    return;
  }
  if (num4 > a.size() / 2 || num7 > a.size() / 2) {
    return;
  }
  if (x.size() == a.size()) {
    if (num4 == num7 && x >= a) {
      if (x < ans || ans == "") {
        ans = x;
        return;
      }
    }
  }
  if (flag == true) {
    ans = x;
    while (num4 < a.size() / 2) {
      ans += '4';
      num4++;
    }
    while (num7 < a.size() / 2) {
      ans += '7';
      num7++;
    }
    return;
  }
  if (a[pos] <= '4') {
    x += "4";
    Dfs(num4 + 1, num7, pos + 1, (a[pos] != '4'));
    x.erase(x.size() - 1, 1);
  }
  if (a[pos] <= '7') {
    x += "7";
    Dfs(num4, num7 + 1, pos + 1, (a[pos] != '7'));
    x.erase(x.size() - 1, 1);
  }
  return;
}
int main() {
  cin >> a;
  if (Judge()) {
    Dfs(0, 0, 0, false);
  } else {
    Deal();
  }
  cout << ans << endl;
  return 0;
}
