#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T GCD(T a, T b) {
  a = abs(a);
  b = abs(b);
  while (b) {
    a = a % b;
    swap(a, b);
  }
  return a;
}
template <typename T>
inline T LCM(T x, T y) {
  T tp = GCD(x, y);
  if ((x / tp) * 1. * y > 9e18) return 9e18;
  return (x / tp) * y;
}
template <typename T>
inline T BigMod(T A, T B, T M) {
  T ret = 1;
  while (B) {
    if (B & 1) ret = (ret * A) % M;
    A = (A * A) % M;
    B = B >> 1;
  }
  return ret;
}
template <typename T>
inline T InvMod(T A, T M) {
  return BigMod(A, M - 2, M);
}
long long gcdr(long long a, long long b) {
  if (a == 0) return b;
  return gcdr(b % a, a);
}
long long poW(long long x, long long n) {
  if (n == 0)
    return 1;
  else if (n % 2 == 0)
    return poW(x * x, n / 2);
  else
    return x * poW(x * x, ((n - 1) / 2));
}
long long max(long long a, long long b) {
  if (a > b) return a;
  return b;
}
long long min(long long a, long long b) {
  if (a < b) return a;
  return b;
}
void FastIO() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(20);
}
int main() {
  FastIO();
  long long t, i, j, n, x, y;
  t = 1;
  while (t--) {
    string s;
    cin >> s;
    long long zeros = 0;
    long long sz = s.size();
    reverse(s.begin(), s.end());
    if (sz < 3) {
      cout << "-1" << endl;
      continue;
    }
    long long ans = -1, flag = 0, last = sz - 1;
    for (i = 1; i <= 7 && i < sz; i++) {
      long long cnt = 0;
      for (long long ii = last; ii > (last - i); ii--) {
        if (s[ii] == '0') {
          cnt++;
        } else {
          break;
        }
      }
      if (cnt > 1) {
        continue;
      }
      if (cnt == 1 && i > 1) {
        continue;
      }
      long long exp = i - 1;
      long long first = 0, second = 0, third = 0;
      for (long long ii = last; ii > (last - i) && ii > 0; ii--) {
        first += ((s[ii] - '0') * poW(10, exp));
        exp--;
      }
      for (j = 1; j <= 7 && j < sz; j++) {
        long long zero = 0;
        second = 0;
        third = 0;
        for (long long jj = last - i; jj > (last - i - j) && jj > 0; jj--) {
          if (s[jj] == '0') {
            zero++;
          } else {
            break;
          }
        }
        if (zero > 1) {
          continue;
        }
        if (zero == 1 && j > 1) {
          continue;
        }
        exp = j - 1;
        for (long long jj = last - i; jj > (last - i - j); jj--) {
          second += ((s[jj] - '0') * poW(10, exp));
          exp--;
        }
        long long used = i + j;
        long long rem = sz - used;
        if (rem > 7 || rem < 1) {
          continue;
        }
        exp = rem - 1;
        zero = 0;
        for (long long k = last - i - j; k >= 0; k--) {
          if (s[k] == '0') {
            zero++;
          } else {
            break;
          }
        }
        if (zero > 1) {
          continue;
        } else if (zero == 1 && rem > 1) {
          continue;
        }
        for (long long k = last - i - j; k >= 0; k--) {
          third += ((s[k] - '0') * poW(10, exp));
          exp--;
        }
        if (first > 1000000 || second > 1e6 || third > 1e6) {
          continue;
        }
        flag = 1;
        ans = max(ans, first + second + third);
      }
    }
    if (flag) {
      cout << ans << endl;
    } else {
      cout << -1 << endl;
    }
  }
  return 0;
}
