#include <bits/stdc++.h>
using namespace std;
int di7[] = {1869, 6189, 1689, 6198, 1698, 8916, 1896};
bool b[] = {0, 1, 0, 0, 0, 0, 1, 0, 1, 1};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  string s;
  int i, r = 0, z = 0;
  cin >> s;
  for (i = 0; i < s.size(); i++) {
    if (b[(int)s[i] - 48])
      b[(int)s[i] - 48] = 0;
    else if (s[i] == '0')
      z++;
    else {
      cout << s[i];
      r = (r * 10 + (int)s[i] - 48) % 7;
    }
  }
  cout << di7[(7 - (r * 10000) % 7) % 7];
  while (z--) cout << 0;
}
