#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
const int INF = 1 << 28;
const long long INFL = 1LL << 62;
int score(string s) {
  if ((int)(s).size() > 1 && s[0] == '0') return -1;
  if ((int)(s).size() > 7) return -1;
  int sum = 0;
  for (int i = 0; i < (int)(s).size(); ++i) {
    sum *= 10;
    sum += (s[i] - '0');
  }
  return (sum > 1000000) ? -1 : sum;
}
int main() {
  string s;
  cin >> s;
  int mx = -1;
  for (int i = 1; i <= min((int)(s).size() - 2, 7); i++) {
    int v1 = score(s.substr(0, i));
    if (v1 == -1) continue;
    for (int j = 1; j <= min((int)(s).size() - i - 1, 7); j++) {
      int v2 = score(s.substr(i, j));
      int v3 = score(s.substr(i + j));
      if (v2 >= 0 && v3 >= 0) mx = max(mx, v1 + v2 + v3);
    }
  }
  cout << mx << endl;
}
