#include <bits/stdc++.h>
using namespace std;
string s;
int x1, x2, x3, x4, j, res = 0, i, n, a[10], c[5];
int main() {
  cin >> s;
  n = s.length();
  for (i = 0; i < n; i++) a[s[i] - '0']++;
  a[1]--;
  a[6]--;
  a[8]--;
  a[9]--;
  c[1] = 1;
  c[2] = 6;
  c[3] = 8;
  c[4] = 9;
  if (a[0] == n - 4) {
    cout << 1869;
    for (i = 0; i < n - 4; i++) cout << 0;
    return 0;
  }
  for (i = 9; i >= 0; i--)
    for (j = 0; j < a[i]; j++) res = (res * 10 + i) % 7;
  for (x1 = 1; x1 <= 4; x1++)
    for (x2 = 1; x2 <= 4; x2++)
      if (x2 != x1)
        for (x3 = 1; x3 <= 4; x3++)
          if (x3 != x1 && x3 != x2)
            for (x4 = 1; x4 <= 4; x4++)
              if (x4 != x1 && x4 != x2 && x4 != x3) {
                int xx = (res * 10000 + c[x1] * 1000 + c[x2] * 100 +
                          c[x3] * 10 + c[x4]);
                if (xx % 7 == 0) {
                  for (i = 9; i >= 0; i--)
                    for (j = 0; j < a[i]; j++) cout << i;
                  cout << c[x1] << c[x2] << c[x3] << c[x4];
                  return 0;
                }
              }
  cout << 0;
}
