#include <bits/stdc++.h>
using namespace std;
int buf_i;
int in() {
  scanf("%d", &buf_i);
  return buf_i;
}
const int INF = ~(1 << 31);
const long long LINF = ~(1LL << 63);
const double eps = 1e-6;
long long gcd(long long a, long long b) {
  while (b) {
    a %= b;
    swap(a, b);
  }
  return a;
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
int main() {
  string s;
  cin >> s;
  s.erase(find(s.begin(), s.end(), '1'));
  s.erase(find(s.begin(), s.end(), '6'));
  s.erase(find(s.begin(), s.end(), '8'));
  s.erase(find(s.begin(), s.end(), '9'));
  string ss = "1689";
  string b = "";
  int zeros = 0;
  for (int i = 0; i < s.size(); ++i)
    if (s[i] != '0')
      b.push_back(s[i]);
    else
      zeros++;
  do {
    string cur = b + ss;
    vector<int> a(cur.size(), 0);
    for (int i = 0; i < cur.size(); ++i) {
      a[i] = cur[i] - '0';
    }
    for (int i = cur.size() - 1; i > 2; --i) {
      while (a[i] < 0) {
        a[i - 1]--;
        a[i] += 10;
      }
      int c = a[i] * 2;
      a[i - 1] -= c % 10;
      a[i - 2] -= c / 10;
    }
    int d = a[0] * 100 + a[1] * 10 + a[2];
    if (d % 7 == 0) {
      cout << cur;
      for (int i = 0; i < zeros; ++i) printf("0");
      cout << endl;
      return 0;
    }
  } while (next_permutation(ss.begin(), ss.end()));
  cout << 0 << endl;
  return 0;
}
