#include <bits/stdc++.h>
using namespace std;
long long *tol(string s) {
  long long *ans = (long long *)(malloc(5 * sizeof(long long)));
  long long len_s = s.size();
  long long i = 0;
  while (i < 5 - len_s) {
    ans[i++] = 0;
  }
  long long j = 0;
  while (j < len_s) {
    if (s[j] <= 58)
      ans[i++] = (long long)(s[j++]) - 48;
    else {
      ans[i++] = (long long)(s[j++]) - 55;
    }
  }
  return ans;
}
long long con(long long *a, long long b) {
  long long ans = 0;
  long long x = 1;
  for (long long i = 4; i >= 0; i--, x = x * b) ans += (a[i] * x);
  return ans;
}
int main() {
  string s;
  cin >> s;
  long long i = 0;
  long long len_s = s.size();
  string a, b;
  a = "";
  b = "";
  while (s[i] != ':') {
    a.push_back(s[i]);
    i++;
  }
  i++;
  while (i < len_s) {
    b.push_back(s[i]);
    i++;
  }
  long long *a1, *b1;
  a1 = tol(a);
  b1 = tol(b);
  long long m = 0;
  for (long long i = 0; i < 5; i++) {
    if (m < a1[i]) m = a1[i];
    if (m < b1[i]) m = b1[i];
  }
  long long ans = 60;
  for (long long i = 59; i > m; i--) {
    long long x = con(a1, i);
    long long y = con(b1, i);
    if ((x < 24) && (y < 60)) {
      ans = i;
      break;
    }
  }
  if (ans == 60)
    cout << 0 << endl;
  else {
    long long flag1 = 0, flag2 = 0;
    for (long long i = 0; i < 4; i++) {
      if (a1[i] != 0) flag1 = 1;
      if (b1[i] != 0) flag2 = 1;
    }
    if ((flag1 == 0) && (flag2 == 0)) {
      if ((a1[4] < 24) && (b1[4] < 60))
        cout << -1 << endl;
      else {
        cout << 0 << endl;
      }
    } else {
      for (long long i = m + 1; i <= ans; i++) cout << i << " ";
      cout << endl;
    }
  }
}
