#include <bits/stdc++.h>
using namespace std;
bool sortinrev(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.first > b.first);
}
double gcd(double a, double b) {
  if (b == 0) return a;
  return gcd(b, double(int(a) % int(b)));
}
long long int power(long long int b, long long int e, long long int m) {
  if (e == 0) return 1;
  if (e & 1) return b * power(b * b % m, e / 2, m) % m;
  return power(b * b % m, e / 2, m);
}
void solve() {
  string s;
  cin >> s;
  string ans;
  long long int z1 = 0, z8 = 0, z6 = 0, z9 = 0, z = 0, c = 0;
  for (long long int i = 0; i < s.length(); i++) {
    if (s[i] == '6' && z6 == 0) {
      z6++;
      continue;
    }
    if (s[i] == '8' && z8 == 0) {
      z8++;
      continue;
    }
    if (s[i] == '1' && z1 == 0) {
      z1++;
      continue;
    }
    if (s[i] == '9' && z9 == 0) {
      z9++;
      continue;
    }
    if (s[i] == '0') {
      c++;
      continue;
    }
    ans.push_back(s[i]);
    z = z * 10 + (s[i] - '0') % 7;
    z %= 7;
  }
  if (z == 0) ans += "1869";
  if (z == 1) ans += "6891";
  if (z == 2) ans += "1896";
  if (z == 3) ans += "1689";
  if (z == 4) ans += "9861";
  if (z == 5) ans += "6189";
  if (z == 6) ans += "1698";
  for (long long int i = 0; i < c; i++) ans.push_back('0');
  cout << ans << '\n';
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t = 1;
  for (long long int i = 0; i < t; i++) {
    solve();
  }
  return 0;
}
