#include <bits/stdc++.h>
using namespace std;
const int N = 1;
string s, b;
int n, ok[10], cnt, k;
int main() {
  cin >> s;
  for (int i = 0; i < s.size(); i++) {
    if ((s[i] == '1' || s[i] == '6' || s[i] == '9' || s[i] == '8') &&
        !ok[(s[i] - '0')]) {
      ok[(s[i] - '0')] = 1;
      b += s[i];
      continue;
    }
    if (s[i] == '0') {
      cnt++;
      continue;
    }
    k = (k * 10 + (s[i] - '0')) % 7;
    cout << s[i];
  }
  sort(b.begin(), b.end());
  do {
    int f = k;
    for (int i = 0; i < b.size(); i++) f = (f * 10 + (b[i] - '0')) % 7;
    if (!f) {
      cout << b;
      break;
    }
  } while (next_permutation(b.begin(), b.end()));
  for (int i = 0; i < cnt; i++) cout << '0';
  return 0;
}
