#include <bits/stdc++.h>
using namespace std;
int c2i(char c) { return c <= '9' ? c - '0' : c - 'A' + 10; }
int conv(string s, int r) {
  int ret = 0;
  for (int i = 0, _n = (int)((int((s).size()))); i < _n; i++)
    if (c2i(s[i]) >= r) return -1;
  for (int i = 0, _n = (int)((int((s).size()))); i < _n; i++) {
    ret = ret * r + c2i(s[i]);
    if (ret > 1000) return -1;
  }
  return ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  string str;
  cin >> str;
  string a, b;
  for (int i = 0, _n = (int)((int((str).size()))); i < _n; i++)
    if (str[i] != ':')
      a += str[i];
    else
      break;
  for (int i = (int)((int((str).size()))), _x = (int)(0); i-- > _x;)
    if (str[i] != ':')
      b = str[i] + b;
    else
      break;
  vector<int> ans;
  for (int r = (int)(2), _n = (int)(1000); r < _n; r++) {
    int x = conv(a, r);
    int y = conv(b, r);
    if (0 <= x && x < 24 && 0 <= y && y < 60) ans.push_back(r);
  }
  if ((int((ans).size())) == 0)
    cout << 0 << endl;
  else if ((int((ans).size())) > 100)
    cout << -1 << endl;
  else {
    for (int i = 0, _n = (int)((int((ans).size()))); i < _n; i++)
      cout << ans[i] << ' ';
    cout << endl;
  }
  {
    int _;
    cin >> _;
    return 0;
  }
}
