#include <bits/stdc++.h>
using namespace std;
const long long N = 1e3 + 5;
vector<long long> v;
void lucky(long long n) {
  if (n > 1e8) {
    return;
  }
  v.push_back(10 * n + 4);
  v.push_back(10 * n + 7);
  lucky(10 * n + 4);
  lucky(10 * n + 7);
}
long long SL(long long n) {
  string s = to_string(n);
  long long m = (long long)((s).size());
  if (m % 2) return -1;
  sort((s).begin(), (s).end());
  m /= 2;
  if (s[m] == '7' && s[m - 1] == '4') {
    return 1;
  }
  return -1;
}
void solve() {
  lucky(0);
  v.push_back(4444477777);
  sort((v).begin(), (v).end());
  long long n;
  cin >> n;
  for (long long i = 0; i < (long long)((v).size()); i++) {
    if (v[i] >= n && SL(v[i]) == 1) {
      cout << v[i] << ' ';
      return;
    }
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) solve();
  return 0;
}
