#include <bits/stdc++.h>
using namespace std;
const int OO = 0x3f3f3f3f;
int main() {
  string in, b, a;
  vector<int> res;
  cin >> in;
  int Max = -1;
  for (long long i = 0; i < in.size(); ++i) {
    if (in[i] >= '0' && in[i] <= '9') {
      Max = max(Max, in[i] - '0');
    } else if (in[i] >= 'A' && in[i] <= 'Z') {
      Max = max(Max, in[i] - 'A' + 10);
    }
  }
  bool inf = true;
  int ares1 = -1, ares2 = -1, bres1 = 0, bres2 = 0;
  while (ares1 != bres1 || ares2 != bres2) {
    ares1 = bres1;
    ares2 = bres2;
    bres1 = 0;
    bres2 = 0;
    Max++;
    bool f = true;
    int c = 0;
    for (long long i = in.size() - 1; i > -1; --i) {
      if (in[i] == ':') {
        f = false;
        c = 0;
        continue;
      }
      if (f) {
        bres2 += in[i] >= '0' && in[i] <= '9'
                     ? (in[i] - '0') * pow(Max, c++)
                     : (in[i] - 'A' + 10) * pow(Max, c++);
      } else {
        bres1 += in[i] >= '0' && in[i] <= '9'
                     ? (in[i] - '0') * pow(Max, c++)
                     : (in[i] - 'A' + 10) * pow(Max, c++);
      }
    }
    if (bres1 > 23 || bres2 > 59) {
      inf = false;
      break;
    } else {
      res.push_back(Max);
    }
  }
  if (inf) {
    cout << -1;
    return 0;
  }
  if (res.empty()) {
    cout << 0;
    return 0;
  }
  for (long long i = 0; i < res.size(); ++i) cout << res[i] << " ";
  return 0;
}
