#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int i, st = 0;
  for (i = 0; i < s.length(); i++) {
    if (s[i] == ':') continue;
    if (s[i] >= 'A' && s[i] <= 'Z') {
      st = max(st, s[i] - 'A' + 10);
    } else
      st = max(st, s[i] - '0');
  }
  for (i = 0; i < s.length(); i++)
    if (s[i] == ':') break;
  string h, m;
  h = s.substr(0, i);
  m = s.substr(i + 1, s.length() - i);
  for (i = 0; i < h.length(); i++)
    if (h[i] != '0') break;
  h = h.substr(i, h.length() - i);
  for (i = 0; i < m.length(); i++)
    if (m[i] != '0') break;
  m = m.substr(i, m.length() - i);
  if (h.length() <= 1 && m.length() <= 1) {
    if (h.length() == 1 && h[0] >= 'O')
      cout << 0;
    else
      cout << -1;
  } else {
    vector<int> ans, ans1;
    for (int i = st + 1; i <= 59; i++) {
      int t = 0;
      for (int j = 0; j < h.length(); j++) {
        if (h[j] >= 'A' && h[j] <= 'Z')
          t += (h[j] - 'A' + 10) * pow(i, h.length() - j - 1);
        else
          t += (h[j] - '0') * pow(i, h.length() - j - 1);
      }
      if (t <= 23) ans.push_back(i);
    }
    for (int i = 0; i < ans.size(); i++) {
      int t = 0;
      for (int j = 0; j < m.length(); j++) {
        if (m[j] >= 'A' && m[j] <= 'Z')
          t += (m[j] - 'A' + 10) * pow(ans[i], m.length() - j - 1);
        else
          t += (m[j] - '0') * pow(ans[i], m.length() - j - 1);
      }
      if (t <= 59) ans1.push_back(ans[i]);
    }
    if (ans1.size() == 0) {
      cout << 0;
      return 0;
    }
    for (i = 0; i < ans1.size(); i++) cout << ans1[i] << " ";
  }
}
