#include <bits/stdc++.h>
using namespace std;
char str[1000010];
int a[1000010];
int main() {
  while (cin >> str) {
    int n = strlen(str);
    for (int i = 0; i < n; i++) a[i] = str[i] - '0';
    for (int i = 0; i < n; i++)
      if (a[i] == 1) {
        swap(a[i], a[n - 4]);
        break;
      }
    for (int i = 0; i < n; i++)
      if (a[i] == 8) {
        swap(a[i], a[n - 3]);
        break;
      }
    for (int i = 0; i < n; i++)
      if (a[i] == 6) {
        swap(a[i], a[n - 2]);
        break;
      }
    for (int i = 0; i < n; i++)
      if (a[i] == 9) {
        swap(a[i], a[n - 1]);
        break;
      }
    int tmp = 0;
    for (int i = 0; i < n - 4; i++) {
      if (a[i] == 0) continue;
      tmp *= 10;
      tmp += a[i];
      tmp %= 7;
    }
    for (int i = 0; i < n - 4; i++)
      if (a[i] != 0) printf("%d", a[i]);
    if (tmp == 0)
      printf("1869");
    else if (tmp == 1)
      cout << "6198";
    else if (tmp == 2)
      cout << "1896";
    else if (tmp == 3)
      cout << "1689";
    else if (tmp == 4)
      cout << 1986;
    else if (tmp == 5)
      cout << 6189;
    else
      cout << 1698;
    for (int i = 0; i < n; i++)
      if (a[i] == 0) cout << 0;
    cout << endl;
  }
  return 0;
}
