#include <bits/stdc++.h>
using namespace std;
void customrun() {}
void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
bool isprime(long long n) {
  for (long long i = 2; (long long)i * i <= n; i++) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}
long long fib(int n) {
  long long a = 0, b = 1, c, i;
  if (n == 0) return a;
  for (i = 2; i <= n; i++) {
    c = (a + b);
    a = b;
    b = c;
  }
  return b;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long extendedgcd(long long a, long long b, long long &x, long long &y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  long long x1, y1;
  long long d = extendedgcd(b, a % b, x1, y1);
  x = y1;
  y = x1 - y1 * (a / b);
  return d;
}
long long findgrouplcm(vector<int> &arr, int n) {
  long long ans = arr[0];
  for (long long i = 1; i < n; i++) ans = (arr[i] * (ans / (gcd(arr[i], ans))));
  return ans;
}
long long powerwithmod(long long x, unsigned long long y, long long p) {
  long long res = 1;
  x = x % p;
  if (x == 0) return 0;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
bool comp(const pair<long, long> &a, const pair<long, long> &b) {
  if (a.first == b.first) return a.second < b.second;
  return a.first < b.first;
}
void solve();
int main() {
  clock_t begin = clock();
  fast();
  customrun();
  long long t = 1;
  for (long long i = (1); i < (t + 1); i += (1)) {
    solve();
  }
  clock_t end = clock();
  return 0;
}
long long power(long long a, long long b) {
  if (b == 0) return 1;
  long long temp = power(a, b / 2);
  temp *= temp;
  if (b & 1) temp *= a;
  return temp;
}
void solve() {
  string num;
  cin >> (num);
  int n = num.size(), fre[10] = {0};
  for (long long i = 0; i < n; i++) {
    fre[num[i] - '0']++;
  }
  string res = "";
  for (long long i = (1); i < (10); i += (1)) {
    if (i == 1 or i == 6 or i == 8 or i == 9) {
      for (long long j = 0; j < fre[i] - 1; j++) {
        res += (i + '0');
      }
    } else {
      for (long long j = 0; j < fre[i]; j++) {
        res += (i + '0');
      }
    }
  }
  string l = "1689";
  vector<string> v;
  string zero = "";
  for (long long i = 0; i < fre[0]; i++) zero += '0';
  do {
    string temp = (res + l + zero);
    v.push_back(temp);
  } while (next_permutation(l.begin(), l.end()));
  for (long long i = 0; i < v.size(); i++) {
    long long p = 0;
    for (long long j = 0; j < n; j++) {
      p = p * 10 + (v[i][j] - '0');
      p = p % 7;
    }
    if (p == 0) {
      cout << (v[i]);
      return;
    }
  }
}
