#include <bits/stdc++.h>
using namespace std;
void func(vector<string>& v, int a, int b, int n, int total, string s) {
  if (total == n && a == b) {
    v.push_back(s);
    return;
  }
  if (total == n) return;
  func(v, a + 1, b, n, total + 1, s + "4");
  func(v, a, b + 1, n, total + 1, s + "7");
}
int main() {
  string s;
  cin >> s;
  int n = s.length();
  int flag = 1;
  if (n % 2 == 0) {
    flag = 2;
    vector<string> v;
    func(v, 0, 0, n, 0, "");
    sort((v).begin(), (v).end());
    for (auto item : v) {
      if (item >= s) {
        cout << item;
        return 0;
      }
    }
  }
  n += flag;
  n = n / 2;
  for (int i = 0; i < n; i++) {
    cout << 4;
  }
  for (int i = 0; i < n; i++) cout << 7;
  return 0;
}
