#include <bits/stdc++.h>
using namespace std;
vector<int> nums;
int mod[100];
char in[1000010];
int cnt[100];
int main() {
  int i, j, k;
  nums.push_back(1);
  nums.push_back(6);
  nums.push_back(8);
  nums.push_back(9);
  sort(nums.begin(), nums.end());
  do {
    int sum = 0;
    for (i = 0; i < 4; i++) {
      sum *= 10;
      sum += nums[i];
    }
    mod[sum % 7] = sum;
  } while (next_permutation(nums.begin(), nums.end()));
  int ok = 1;
  int n;
  scanf("%s", in);
  n = strlen(in);
  for (i = 0; i < n; i++) {
    cnt[in[i] - '0']++;
  }
  for (i = 0; i < 4; i++) {
    cnt[nums[i]]--;
  }
  int now = 0;
  for (i = 9; i >= 1; i--) {
    while (cnt[i]--) {
      now *= 10;
      now += i;
      now %= 7;
      printf("%d", i);
    }
  }
  now *= 10000;
  now %= 7;
  printf("%d", mod[(7 - now) % 7]);
  while (cnt[i]--) {
    printf("%d", i);
  }
  return 0;
}
