#include <bits/stdc++.h>
using namespace std;
long long n, x, y, i, j;
set<long long> a, b;
stack<long long> c;
bool ch(long long n) {
  long long f = 0, s = 0;
  while (n) {
    if (n % 10 == 4) f++;
    if (n % 10 == 7) s++;
    n /= 10;
  }
  return f == s;
}
int main() {
  c.push(4);
  c.push(7);
  while (!c.empty()) {
    x = c.top();
    c.pop();
    if (b.count(x) != 0) continue;
    b.insert(x);
    if (ch(x)) a.insert(x);
    y = x * 10 + 4;
    if (y <= 4444477777) c.push(y);
    y = x * 10 + 7;
    if (y <= 4444477777) c.push(y);
  }
  cin >> n;
  cout << *lower_bound(a.begin(), a.end(), n) << endl;
  return 0;
}
