#include <bits/stdc++.h>
using namespace std;
char str[1000010];
bool vis[1000010];
int main() {
  while (~scanf("%s", str)) {
    int find[5] = {0};
    int len = strlen(str);
    int num = 0, ans, res = 0;
    memset(vis, 0, sizeof(vis));
    for (int i = 0; i < len; i++) {
      if (str[i] == '1' && !find[0])
        find[0] = 1, vis[i] = 1;
      else if (str[i] == '8' && !find[1])
        find[1] = 1, vis[i] = 1;
      else if (str[i] == '9' && !find[2])
        find[2] = 1, vis[i] = 1;
      else if (str[i] == '6' && !find[3])
        find[3] = 1, vis[i] = 1;
      else if (str[i] == '0')
        num++, vis[i] = 1;
    }
    for (int i = 0; i < len; i++)
      if (vis[i] == 0) {
        printf("%c", str[i]);
        res = res * 10 + str[i] - '0';
        res %= 7;
      }
    char p[] = "1689";
    do {
      ans = res;
      for (int i = 0; i < 4; i++) ans = ans * 10 + p[i] - '0', ans = ans % 7;
      if (ans == 0) break;
    } while (next_permutation(p, p + 4));
    printf("%s", p);
    for (int i = 0; i < num; i++) printf("0");
    puts("");
  }
  return 0;
}
