#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5, MOD = 1e9 + 7;
long long int t, n, m, ans, c, sum, y, mn = 1e9;
string s;
vector<long long int> v;
string x[10] = {"47",       "4477",       "444777",
                "44447777", "4444477777", "444444777777"};
void init() {
  for (int i = 0; i < 6; i++) do {
      v.push_back(stoll(x[i]));
    } while (next_permutation(x[i].begin(), x[i].end()));
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  ;
  init();
  cin >> n;
  sort(v.begin(), v.end());
  for (int i = 0; i < v.size(); i++) {
    if (v[i] >= n) {
      cout << v[i] << '\n';
      break;
    }
  }
  return 0;
}
