#include #include #include #include int main() { using namespace std; auto perm_gcd = [&](string s) -> string { int n = s.size(); sort(s.begin(), s.end()); if (s[0] == s[n - 1]) { return s; } int g = s[n - 1] - '0', tot = 0; for (char c : s) { g = gcd(g, c - '0'); tot = (tot + c - '0') % 9; } if (tot > 0) { return "1"; } if (g < 9) { return to_string(g * 9); } return "9"; }; string s; cin >> s; cout << perm_gcd(s) << endl; }