#include <bits/stdc++.h>
using namespace std;
string s;
string a[7];
int c[10];
int pow2[] = {1, 2, 4, 8};
int pow5[] = {1, 5, 25, 125, 625, 3125, 15625, 78125};
bool OK(int);
string toString(int);
int main() {
  cin >> s;
  for (int x = 1000; x <= 9999; x++) {
    if (OK(x)) {
      a[x % 7] = toString(x);
    }
  }
  c[1] = c[6] = c[8] = c[9] = 1;
  int i = 0;
  while (i < s.length()) {
    if (c[s[i] - '0'] == 1 || s[i] == 0) {
      c[s[i] - '0'] = 0;
      s.erase(i, 1);
    } else {
      i++;
    }
  }
  int n = s.length();
  for (int i = 0; i < n; i++) {
    if (s[i] != '0') {
      swap(s[i], s[0]);
      break;
    }
  }
  if (n > 0 && s[0] == '0') {
    cout << a[0] << s << endl;
    return 0;
  }
  int mod7 = 0;
  for (int i = 0; i < n; i++) {
    int k = n - i - 1;
    int tmod7 = (pow2[k % 3] % 7 * pow5[k % 6] % 7) % 7;
    tmod7 = ((s[i] - '0') * tmod7) % 7;
    mod7 = (mod7 + tmod7) % 7;
  }
  mod7 = (mod7 * 4) % 7;
  cout << s << a[(7 - mod7) % 7] << endl;
  return 0;
}
string toString(int x) {
  string ret = "";
  while (x > 0) {
    ret = char('0' + x % 10) + ret;
    x = x / 10;
  }
  return ret;
}
bool OK(int x) {
  int ret[10];
  for (int i = 0; i < 10; i++) {
    ret[i] = 0;
  }
  while (x > 0) {
    ret[x % 10]++;
    x = x / 10;
  }
  return (ret[1] == 1 && ret[6] == 1 && ret[8] == 1 && ret[9] == 1);
}
