#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int len = s.length();
  vector<int> ivv;
  if (len == 4) {
    cout << 1869 << endl;
    return 0;
  }
  string str = "";
  string sO = "";
  bool b1 = false, b2 = false, b3 = false, b4 = false;
  bool b5 = false;
  string kk;
  int un;
  for (int i = 0; i < len; i++) {
    if (s[i] == '0') {
      sO += '0';
      continue;
    }
    if (s[i] == '1' && b1 == false) {
      b1 = true;
      continue;
    } else if (s[i] == '6' && b2 == false) {
      b2 = true;
      continue;
    } else if (s[i] == '8' && b3 == false) {
      b3 = true;
      continue;
    } else if (s[i] == '9' && b4 == false) {
      b4 = true;
      continue;
    } else {
      kk = s[i];
      istringstream ist(kk);
      ist >> un;
      ivv.push_back(un);
      str += s[i];
      b5 = true;
    }
  }
  string result = "";
  result += str;
  int len1 = result.length();
  int oct;
  unsigned int sv = ivv.size();
  if (b5 == true) {
    oct = 0;
    int z = ivv[0];
    for (int i = 0; i < sv; i++) {
      z = oct + ivv[i];
      if (z < 7) {
        oct = ivv[i] * 10;
        continue;
      }
      if (z % 7 == 0) {
        oct = 0;
        continue;
      } else {
        oct = (z % 7) * 10;
      }
    }
    oct /= 10;
    if (oct == 0) {
      result += "1869";
    } else if (oct == 1) {
      result += "6891";
    } else if (oct == 2) {
      result += "1896";
    } else if (oct == 3) {
      result += "1689";
    } else if (oct == 4) {
      result += "1986";
    } else if (oct == 5) {
      result += "1968";
    } else if (oct == 6) {
      result += "1698";
    }
  } else {
    result = "1869";
  }
  result += sO;
  cout << result << endl;
  return 0;
}
