#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  ;
  long long a;
  cin >> a;
  queue<pair<long long, long long>> q;
  q.push(make_pair(0, 0));
  while (!q.empty()) {
    long long d, c;
    d = q.front().first;
    c = q.front().second;
    q.pop();
    if (d >= a && c == 0) {
      cout << d;
      break;
    }
    q.push(make_pair(d * 10 + 4, c + 1));
    q.push(make_pair(d * 10 + 7, c - 1));
  }
  return 0;
}
