#include <bits/stdc++.h>
using namespace std;
int convert(string s, int base) {
  int p = 1, res = 0;
  for (int i = s.size() - 1; i >= 0; i--) {
    int cur;
    if (s[i] >= 'A') {
      cur = s[i] - 'A' + 10;
    } else {
      cur = s[i] - '0';
    }
    res += cur * p;
    p = p * base;
  }
  return res;
}
int main() {
  string s, s1 = "", s2 = "";
  cin >> s;
  int i = 0;
  while (s[i] != ':') {
    s1 = s1 + s[i];
    i++;
  }
  i++;
  while (i < s.size()) {
    s2 = s2 + s[i];
    i++;
  }
  int max = 0;
  for (int i = 0; i < s1.size(); i++) {
    if (s1[i] > max) {
      max = s1[i];
    }
  }
  for (int i = 0; i < s2.size(); i++) {
    if (s2[i] > max) {
      max = s2[i];
    }
  }
  if (max >= 'A') {
    max = max - 'A' + 10;
  } else {
    max = max - '0';
  }
  if (convert(s1, max + 1) > 23) {
    cout << "0\n";
    return 0;
  }
  if (convert(s2, max + 1) > 59) {
    cout << "0\n";
    return 0;
  }
  while (s1.size() > 1) {
    if (s1[0] == '0') {
      s1.erase(s1.begin());
    } else {
      break;
    }
  }
  while (s2.size() > 1) {
    if (s2[0] == '0') {
      s2.erase(s2.begin());
    } else {
      break;
    }
  }
  if (s1.size() == 1 && s2.size() == 1) {
    cout << "-1\n";
    return 0;
  }
  int res1 = 0, res2 = 0;
  int cbase = max + 1;
  if (s1.size() > 1) {
    while (convert(s1, cbase) < 24) {
      cbase++;
      res1++;
    }
  } else {
    res1 = 1000000000;
  }
  cbase = max + 1;
  if (s2.size() > 1) {
    while (convert(s2, cbase) < 60) {
      cbase++;
      res2++;
    }
  } else {
    res2 = 1000000000;
  }
  if (res1 < res2) {
    for (int i = 0; i < res1; i++) {
      cout << (max + 1 + i) << " ";
    }
  } else {
    for (int i = 0; i < res2; i++) {
      cout << (max + 1 + i) << " ";
    }
  }
  cout << endl;
  return 0;
}
