#include <bits/stdc++.h>
using namespace std;
string s;
string f1;
int bagh() {
  int t = 0;
  for (int j = 0; j < f1.length(); j++) {
    t *= 10;
    t += (f1[j] - '0');
    t %= 7;
  }
  for (int i = 0; i < s.length(); i++) {
    t *= 10;
    t += (s[i] - '0');
    t %= 7;
  }
  return t;
}
int main() {
  ios::sync_with_stdio("false");
  string n;
  cin >> n;
  f1 = "1689";
  int x1 = 1, x8 = 1, x6 = 1, x9 = 1;
  for (int i = 0; i < n.length(); i++) {
    if (n[i] == '1' and x1 == 1)
      x1--;
    else if (n[i] == '6' and x6 == 1)
      x6--;
    else if (n[i] == '8' and x8 == 1)
      x8--;
    else if (n[i] == '9' and x9 == 1)
      x9--;
    else
      s.push_back(n[i]);
  }
  do {
    if (bagh() == 0) {
      for (int j = 0; j < f1.length(); j++) cout << f1[j];
      for (int j = 0; j < s.length(); j++) cout << s[j];
      return 0;
    }
  } while (next_permutation(f1.begin(), f1.end()));
  cout << 0;
}
