#include <bits/stdc++.h>
namespace patch {
template <typename T>
std::string to_string(const T& n) {
  std::ostringstream stm;
  stm << n;
  return stm.str();
}
}  // namespace patch
using namespace std;
int main() {
  map<char, long long int> mp;
  for (char i = '0'; i <= '9'; i++) {
    mp[i] = (i - '0');
  }
  for (int i = 'A', j = 10; i <= 'Z'; i++, j++) {
    mp[i] = j;
  }
  string S, a, b;
  long long int mx = 0;
  cin >> S;
  bool flag = false, c = false;
  for (int i = 0; i < S.size(); i++) {
    if (S[i] == ':') {
      c = true;
      flag = false;
      continue;
    }
    if (S[i] != '0') {
      flag = true;
    }
    if (flag) {
      if (!c) {
        a += S[i];
      } else {
        b += S[i];
      }
    }
    mx = max(mx, mp[S[i]]);
  }
  if (a.size() == 0) {
    a = "0";
  }
  if (b.size() == 0) {
    b = "0";
  }
  mx++;
  if (a.size() == 1 && b.size() == 1) {
    if (mp[a[0]] >= 24) {
      cout << 0;
    } else {
      cout << -1;
    }
    return 0;
  }
  bool chk = false;
  while (1) {
    long long int HH, MM, w8 = 1;
    HH = MM = 0;
    for (int i = a.size() - 1; i >= 0; i--) {
      HH += mp[a[i]] * w8;
      w8 *= mx;
    }
    w8 = 1;
    for (int i = b.size() - 1; i >= 0; i--) {
      MM += mp[b[i]] * w8;
      w8 *= mx;
    }
    if (HH < 24 && MM < 60) {
      cout << mx << " ";
      chk = true;
    } else {
      break;
    }
    mx++;
  }
  if (!chk) {
    cout << 0;
  }
  return 0;
}
