#include <bits/stdc++.h>
const int M = 1e5 + 7;
const long long N = 2e9 + 9;
using namespace std;
int n;
queue<pair<long long, int> > q;
int main() {
  scanf("%d", &n);
  q.push(make_pair(0, 0));
  while (1) {
    long long x = q.front().first;
    int y = q.front().second;
    q.push(make_pair(x * 10 + 4, y + 1));
    if (q.back().first >= n && q.back().second == 0) {
      cout << q.back().first;
      return 0;
    }
    q.push(make_pair(x * 10 + 7, y - 1));
    if (q.back().first >= n && q.back().second == 0) {
      cout << q.back().first;
      return 0;
    }
    q.pop();
  }
  return 0;
}
