#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (a > b) swap(a, b);
  if (a == 0) return b;
  return gcd(b % a, a);
}
long long binpow(long long a, long long b) {
  if (b == 0) return 1;
  long long res = binpow(a, b / 2) % 1000000007;
  if (b % 2)
    return (((long long)res * (long long)res % 1000000007) * (long long)a) %
           1000000007;
  else
    return ((long long)res * (long long)res) % 1000000007;
}
void solve() {
  string s;
  cin >> s;
  string t;
  int one = 1, six = 1, eig = 1, nine = 1, zr = 0;
  for (char c : s) {
    if (c == '1' && one) {
      one = 0;
      continue;
    }
    if (c == '6' && six) {
      six = 0;
      continue;
    }
    if (c == '8' && eig) {
      eig = 0;
      continue;
    }
    if (c == '9' && nine) {
      nine = 0;
      continue;
    }
    if (c == '0') {
      zr++;
      continue;
    }
    t.push_back(c);
  }
  int pre = 0;
  for (int i = 0; i < t.size(); i++) {
    pre = ((pre * 10 % 7) + (t[i] - '0') % 7) % 7;
  }
  cout << t;
  switch (pre) {
    case 0: {
      cout << "1869";
      break;
    }
    case 1: {
      cout << "6891";
      break;
    }
    case 2: {
      cout << "1896";
      break;
    }
    case 3: {
      cout << "6918";
      break;
    }
    case 4: {
      cout << "1986";
      break;
    }
    case 5: {
      cout << "1968";
      break;
    }
    case 6: {
      cout << "1698";
      break;
    }
  }
  for (int i = 0; i < zr; i++) {
    cout << "0";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int T = 1;
  while (T--) {
    solve();
  }
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
}
