#include <bits/stdc++.h>
using namespace std;
struct print {
  template <typename T>
  print& operator,(const T& v) {
    std::cout << v << " ";
    return *this;
  }
};
int main() {
  long long a[] = {47, 74, 4477, 4747, 4774, 7447, 7474, 7744};
  vector<long long> v(a, a + 8);
  long long n;
  scanf("%lld", &n);
  string str = "4444477777";
  long long t = 0;
  do {
    t = 0;
    for (int i = 0; i < str.size(); i++) {
      t *= 10;
      t += str[i] - '0';
    }
    v.push_back(t);
  } while (next_permutation(str.begin(), str.end()));
  str = "44447777";
  t = 0;
  do {
    t = 0;
    for (int i = 0; i < str.size(); i++) {
      t *= 10;
      t += str[i] - '0';
    }
    v.push_back(t);
  } while (next_permutation(str.begin(), str.end()));
  str = "444777";
  t = 0;
  do {
    t = 0;
    for (int i = 0; i < str.size(); i++) {
      t *= 10;
      t += str[i] - '0';
    }
    v.push_back(t);
  } while (next_permutation(str.begin(), str.end()));
  sort(v.begin(), v.end());
  for (int i = 0; i < v.size(); i++) {
    if (v[i] >= n) {
      print(), v[i], "\n";
      return 0;
    }
  }
  return 0;
}
