import java.io.*; import java.util.*; public class Main_yukicoder437 { private static Scanner sc; private static Printer pr; private static void solve() { String s = sc.next(); int ret = 0; while (s.length() >= 3) { // n個のビットのうち、i個のビットが立っているmaskのパターンの生成 int n = s.length(); int i = 3; int max = 0; int maxm = 0; int mask = (0x1 << i) - 1; while (mask < 0x1 << n) { // maskに対する処理 char[] tmp = new char[3]; int k = 0; for (int j = 0; j < n; j++) { if ((mask & 0x1 << j) != 0) { tmp[k++] = s.charAt(j); } } if (tmp[0] != '0' && tmp[0] != tmp[1] && tmp[1] == tmp[2]) { int cww = Integer.parseInt(new String(tmp)); if (cww > max) { max = cww; maxm = mask; } } // 次のmaskの計算 int x = mask & -mask; int y = mask + x; mask = ((mask & ~y) / x >> 1) | y; } if (max == 0) { break; } else { ret += max; for (int j = n - 1; j >= 0; j--) { if ((maxm & 0x1 << j) != 0) { s = s.substring(0, j) + s.substring(j + 1); } } } } pr.println(ret); } // --------------------------------------------------- public static void main(String[] args) { sc = new Scanner(System.in); pr = new Printer(System.out); solve(); pr.close(); sc.close(); } private static class Printer extends PrintWriter { Printer(PrintStream out) { super(out); } } }