#include <bits/stdc++.h>
using namespace std;
int n;
string s;
int dp[101][11];
int number(int L, int R) {
  if (s[L] == '0' && L != R) return -100000000;
  int ret = 0;
  for (int i = L; i <= R; i++) ret = 10 * ret + s[i] - '0';
  if (ret > 1000000) return -100000000;
  return ret;
}
int main() {
  ios ::sync_with_stdio(false);
  cin >> s;
  n = s.length();
  s = " " + s;
  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= 3; j++) dp[i][j] = -100000000;
  dp[0][0] = 0;
  for (int i = 1; i <= n; i++)
    for (int t = 1; t <= 3; t++)
      for (int j = max(0, i - 7); j < i; j++)
        if (number(j + 1, i) >= 0)
          dp[i][t] = max(dp[i][t], dp[j][t - 1] + number(j + 1, i));
  if (dp[n][3] < 0) dp[n][3] = -1;
  cout << dp[n][3] << endl;
  return 0;
}
