#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  return b ? gcd(b, a % b) : a;
}
long long int lcm(long long int a, long long int b) {
  return a * b / gcd(a, b);
}
int a[7], cnt[10];
string s;
void pre() {
  string s = "1689";
  do {
    int x = atoi(s.c_str());
    int r = x % 7;
    a[r] = x;
  } while (next_permutation(s.begin(), s.end()));
}
bool foo(int n, int rem) {
  int x = 0;
  string s = to_string(n);
  for (auto c : s) {
    int r = c - '0';
    rem = rem * 10 + r;
    rem %= 7;
  }
  return rem == 0;
}
int main() {
  pre();
  cin >> s;
  int n = (int)s.size();
  for (auto c : s) cnt[c - '0']++;
  cnt[1]--, cnt[9]--, cnt[6]--, cnt[8]--;
  int rem = 0;
  for (auto c : s) {
    while (cnt[c - '0'] && (c - '0')) {
      cout << c;
      cnt[c - '0']--;
      rem = (rem * 10 + (c - '0'));
      rem %= 7;
    }
  }
  for (int i = 0; i < 7; i++) {
    if (foo(a[i], rem)) {
      cout << a[i];
      break;
    }
  }
  while (cnt[0]) {
    cout << 0;
    cnt[0]--;
  }
  cout << endl;
  return 0;
}
