#include <bits/stdc++.h>
using namespace std;
bool f1, f6, f8, f9;
int main() {
  string s;
  cin >> s;
  int n = s.size();
  string ns = "";
  int p = 0;
  int st = 1;
  for (int i = 0; i < n; i++) {
    if (s[i] == '1' && !f1) {
      f1 = true;
    } else if (s[i] == '6' && !f6) {
      f6 = true;
    } else if (s[i] == '8' && !f8) {
      f8 = true;
    } else if (s[i] == '9' && !f9) {
      f9 = true;
    } else {
      p *= 10;
      p %= 7;
      p += (int)(s[i] - '0');
      p %= 7;
      ns += s[i];
      st *= 10;
      st %= 7;
    }
  }
  int v = (7 - p) % 7;
  string u = "1689";
  do {
    int k = atoi(u.c_str());
    if (((k * st) % 7) == v) {
      cout << k << ns << endl;
      return 0;
    }
  } while (next_permutation(u.begin(), u.end()));
  return 0;
}
