#include <bits/stdc++.h>
using namespace std;
vector<long long> v;
bool super(string s) {
  int sv = 0, f = 0;
  for (int i = 0; i < s.length(); ++i) {
    (s[i] == '7' ? sv += 1 : f += 1);
  }
  return (sv == f ? true : false);
}
long long strtoll(string s) {
  long long res = 0;
  for (int i = 0; i < s.length(); ++i) {
    res = res * 10 + (s[i] - '0');
  }
  return res;
}
void gennbrs(string s) {
  if (s.length() == 11) return;
  if (s != "" and super(s)) v.push_back(strtoll(s));
  gennbrs(s + '4');
  gennbrs(s + '7');
}
int main() {
  gennbrs("");
  sort(v.begin(), v.end());
  int n;
  scanf("%d", &n);
  for (int i = 0; i < v.size(); ++i) {
    if (v[i] >= n) {
      cout << v[i] << endl;
      break;
    }
  }
  return 0;
}
