#include <bits/stdc++.h>
using namespace std;
int Set(int N, int pos) { return N = N | (1 << pos); }
int reset(int N, int pos) { return N = N & ~(1 << pos); }
bool check(int N, int pos) { return (bool)(N & (1 << pos)); }
void CI(int &_x) { scanf("%d", &_x); }
void CO(int &_x) { cout << _x; }
template <typename T>
void getarray(T a[], int n) {
  for (int i = 0; i < n; i++) cin >> a[i];
}
template <typename T>
void printarray(T a[], int n) {
  for (int i = 0; i < n - 1; i++) cout << a[i] << " ";
  cout << a[n - 1] << endl;
}
const double EPS = 1e-9;
const int INF = 0x7f7f7f7f;
int dr8[8] = {1, -1, 0, 0, 1, -1, -1, 1};
int dc8[8] = {0, 0, -1, 1, 1, 1, -1, -1};
int dr4[4] = {0, 0, 1, -1};
int dc4[4] = {-1, 1, 0, 0};
int kn8r[8] = {1, 2, 2, 1, -1, -2, -2, -1};
int kn8c[8] = {2, 1, -1, -2, -2, -1, 1, 2};
int ar[13] = {0};
int func(string num) {
  int len = num.size();
  int rem = 0;
  for (int i = 0; i < len; i++) {
    rem = ((rem * 10) + (num[i] - '0')) % 7;
  }
  return rem;
}
vector<string> v;
int main() {
  v.push_back("1869");
  v.push_back("1698");
  v.push_back("1968");
  v.push_back("1986");
  v.push_back("1689");
  v.push_back("8196");
  v.push_back("6891");
  string num;
  cin >> num;
  for (int i = 0; i < num.size(); i++) {
    ar[num[i] - '0']++;
  }
  ar[1]--;
  ar[6]--;
  ar[8]--;
  ar[9]--;
  num.clear();
  for (int i = 1; i <= 9; i++) {
    for (int j = 0; j < ar[i]; j++) num.push_back(i + '0');
  }
  int rem = func(num);
  cout << num;
  char ch = rem + '0';
  for (int i = 0; i < v.size(); i++) {
    if (func(ch + v[i]) == 0) {
      cout << v[i];
      break;
    }
  }
  for (int i = 0; i < ar[0]; i++) cout << "0";
  puts("");
  return 0;
}
