#include <bits/stdc++.h>
using namespace std;
long long int numRange(string s, int m, int n) {
  if (m > n) return -1;
  long long int num = 0;
  for (int i = m; i <= n; i++) {
    num += s[i] - '0';
    num *= 10;
  }
  num /= 10;
  return num;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string s;
  cin >> s;
  long long int num1 = 0, num2 = 0, num3 = 0, maxSum = -1;
  for (int i = 0; i < min((int)s.size() - 2, 7); i++) {
    for (int j = i + 1; j < min((int)s.size() - 1, i + 8); j++) {
      num1 = numRange(s, 0, i);
      num2 = numRange(s, i + 1, j);
      num3 = numRange(s, j + 1, s.size() - 1);
      if (s[0] == '0') {
        if (i != 0 || num1 != 0) continue;
      }
      if (s[i + 1] == '0') {
        if (j != i + 1 || num2 != 0) continue;
      }
      if (s[j + 1] == '0') {
        if (j + 2 != s.size() || num3 != 0) continue;
      }
      if (num1 > 1000000 || num1 < 0) {
        continue;
      }
      if (num2 > 1000000 || num2 < 0) {
        continue;
      }
      if (num3 > 1000000 || num3 < 0) {
        continue;
      }
      maxSum = max(maxSum, num1 + num2 + num3);
    }
  }
  if (s.size() > 21 || s.size() < 3) {
    cout << -1 << endl;
  } else {
    cout << maxSum << endl;
  }
  return 0;
}
