#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  int n;
  cin >> n;
  int k = 0;
  int h = 0;
  if (n > 77774444) {
    cout << 4444477777;
    return 0;
  }
  for (int i = n; i <= 1000000000; i++) {
    int j = i;
    h = 0;
    k = 0;
    while (j > 0) {
      if (j % 10 != 4 && j % 10 != 7) {
        h = -1;
        k = 0;
        break;
      }
      if (j % 10 == 4) {
        k++;
      } else {
        h++;
      }
      j = j / 10;
    }
    if (h == k) {
      cout << i << endl;
      break;
    }
  }
  return 0;
}
