#include <bits/stdc++.h>
using namespace std;
vector<int> v;
string n;
long long mini = 1e11;
long long nll = 0;
long long ans = 1e11;
void answer(vector<int> v) {
  string total = " ";
  for (int i = 0; i < v.size(); i++) {
    total += to_string(v[i]);
  }
  stringstream red(total);
  long long p = 0;
  red >> p;
  if (p >= nll) {
    if (p <= ans) {
      ans = min(p, ans);
    }
  }
}
void solve() {
  cin >> n;
  int a = 4, b = 7, cnt = 0;
  int flag = 0, ct = 0;
  stringstream black(n);
  black >> nll;
  for (int i = 0; i < n.size(); i++) {
    if (n[i] == '7') {
      cnt++;
    } else if (n[0] == '4') {
      ct++;
    }
    if (n[i] > '7' && n[0] >= '7' && i != 0) flag = 1;
  }
  if ((flag || cnt > (n.size() / 2)) && !(n.size() % 2)) {
    if (ct == 0) {
      n += "12";
    }
  }
  if ((flag || cnt > (n.size() / 2)) && (n.size() % 2)) {
    n += "1";
  }
  for (int i = 0; i < n.size(); i += 2) {
    v.push_back(a);
    v.push_back(b);
  }
  sort(v.begin(), v.end());
  do {
    answer(v);
  } while (next_permutation(v.begin(), v.end()));
  cout << ans << " " << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
