#include <bits/stdc++.h>
const int inf = 0xfffffff;
const long long INF = 1ll << 61;
using namespace std;
string s;
string str = "1689";
string ans;
void init() {}
bool input() {
  while (cin >> s) {
    return false;
  }
  return true;
}
void cal() {
  ans = "";
  for (int i = 0; i < 4; i++) s.erase(find(s.begin(), s.end(), str[i]));
  int tmp = 0;
  for (int i = 0; i < s.length(); i++) tmp += s[i] - '0';
  if (tmp == 0) {
    ans += "1869";
    ans += s;
    return;
  }
  string ss = "";
  for (int i = 0; i < s.length(); i++) {
    if (s[i] != '0') {
      ss = s.substr(i, s.length() - i) + s.substr(0, i);
      break;
    }
  }
  tmp = 0;
  for (int i = 0; i < ss.length(); i++) tmp = (tmp * 10 + ss[i] - '0') % 7;
  tmp *= 10000;
  tmp %= 7;
  do {
    int now = 0;
    for (int i = 0; i < 4; i++) now = (now * 10 + str[i] - '0');
    now %= 7;
    if ((tmp + now) % 7 == 0) {
      ans += ss;
      ans += str;
      return;
    }
  } while (next_permutation(str.begin(), str.end()));
}
void output() { cout << ans << endl; }
int main() {
  while (true) {
    init();
    if (input()) return 0;
    cal();
    output();
  }
}
