#include <bits/stdc++.h>
using namespace std;
int getHour(char *s1, int len, int base) {
  double hr = 0;
  char *s = new char[10];
  for (int i = 0; i < len; i++) {
    s[i] = s1[i];
  }
  s[len] = 0;
  reverse(s, s + len);
  for (int i = 0; i < len; i++) {
    char p = s[i];
    int r = 0;
    if (p > '9') {
      r = 10 + p - 'A';
    } else {
      r = p - '0';
    }
    hr = hr + (r * pow(base, i));
  }
  return hr;
}
int main() {
  vector<int> ans;
  char *c = new char[20];
  cin >> c;
  char *a = new char[10];
  char *b = new char[10];
  bool f = false;
  int lena = 0;
  int lenb = 0;
  char p = 0;
  for (int i = 0; i < strlen(c); i++) {
    if (c[i] == ':') {
      f = true;
      continue;
    }
    if (c[i] > p) {
      p = c[i];
    }
    if (!f) {
      a[lena++] = c[i];
    } else {
      b[lenb++] = c[i];
    }
  }
  a[lena] = 0;
  b[lenb] = 0;
  int r = 0;
  if (p > '9') {
    r = 10 + p - 'A';
  } else {
    r = p - '0';
  }
  r++;
  for (int i = r; i < 70; i++) {
    if (i > 60) {
      cout << -1;
      return 0;
    }
    int hr = getHour(a, lena, i);
    int minute = getHour(b, lenb, i);
    if (hr < 24 && minute < 60) {
      ans.push_back(i);
    } else {
      break;
    }
  }
  if (ans.size() == 0) {
    cout << 0 << endl;
  }
  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i] << " ";
  }
  return 0;
}
