#include <bits/stdc++.h>
using namespace std;
void fun(int b, int d) {
  int u = 1;
  int v = 0;
  if ((b < 0 && d > 0) || (b > 0 && d < 0)) v = 1;
  b = abs(b);
  d = abs(d);
  if (b < d) {
    swap(b, d);
    u = 0;
  }
  int b1 = b, d1 = d;
  int x = b % d;
  while (x) {
    b = d;
    d = x;
    x = b % d;
  }
  if (u == 0) {
    if (v) d1 *= -1;
    cout << d1 / d << "/" << b1 / d;
  } else {
    if (v) b1 *= -1;
    cout << b1 / d << "/" << d1 / d;
  }
}
int po(int m, int i) {
  int r = 1;
  while (i--) {
    r *= m;
  }
  return r;
}
long long num7(long long x) {
  long long v = 0;
  while (x) {
    if (x % 10 == 7) v++;
    x /= 10;
  }
  return v;
}
long long num4(long long x) {
  long long v = 0;
  while (x) {
    if (x % 10 == 4) v++;
    x /= 10;
  }
  return v;
}
int arr[101];
int main() {
  string s;
  cin >> s;
  vector<int> v1, v2;
  int u = 1;
  for (int i = s.size() - 1; i >= 0; i--) {
    int a;
    if (s[i] == ':') {
      u = 0;
      continue;
    }
    if (isalpha(s[i])) {
      a = s[i] - 'A' + 10;
    } else
      a = s[i] - '0';
    if (u)
      v2.push_back(a);
    else
      v1.push_back(a);
  }
  while (!v1.empty()) {
    if (v1.back() != 0)
      break;
    else
      v1.pop_back();
  }
  while (!v2.empty()) {
    if (v2.back())
      break;
    else
      v2.pop_back();
  }
  int m = 0;
  for (unsigned int i = 0; i < v1.size(); i++) {
    if (v1[i] > m) m = v1[i];
  }
  for (unsigned int i = 0; i < v2.size(); i++) {
    if (v2[i] > m) m = v2[i];
  }
  int l = 0;
  while (1) {
    m++;
    int sumh = 0, summ = 0;
    for (unsigned int i = 0; i < v1.size(); i++) {
      sumh += po(m, i) * v1[i];
    }
    for (unsigned int i = 0; i < v2.size(); i++) {
      summ += po(m, i) * v2[i];
    }
    if (sumh < 24 && summ < 60) {
      l = 1;
      if (v1.size() < 2 && v2.size() < 2) {
        cout << "-1";
        break;
      } else
        cout << m << " ";
    } else {
      if (l)
        break;
      else {
        cout << "0";
        break;
      }
    }
  }
  return 0;
}
