#include <bits/stdc++.h>
using namespace std;
long long int StringToInt(string s) {
  stringstream convert(s);
  long long int N;
  if ((s.size() > 1 && s[0] == '0') || s.size() > 6) {
    N = -1;
    return N;
  } else {
    convert >> N;
    return N;
  }
}
void FindAllPossibleNums(string s, int x[3], vector<long long int> &v,
                         vector<vector<long long int> > &ThreeNums) {
  v.clear();
  for (int i = 0; i < 4; i++) {
    if (i == 0) {
      for (int ii = 1; ii < 3; ii++) {
        v.push_back(StringToInt(s.substr(0, x[i])));
        v.push_back(StringToInt(s.substr(x[i], x[ii])));
        if (ii == 1) {
          v.push_back(StringToInt(s.substr(x[i] + x[ii], x[2])));
        } else {
          v.push_back(StringToInt(s.substr(x[i] + x[ii], x[1])));
        }
        ThreeNums.push_back(v);
        v.clear();
      }
    } else if (i == 1) {
      for (int ii = 0; ii < 2; ii++) {
        v.push_back(StringToInt(s.substr(0, x[i])));
        if (ii == 0) {
          v.push_back(StringToInt(s.substr(x[i], x[0])));
          v.push_back(StringToInt(s.substr(x[i] + x[0], x[2])));
        } else {
          v.push_back(StringToInt(s.substr(x[i], x[2])));
          v.push_back(StringToInt(s.substr(x[i] + x[2], x[0])));
        }
        ThreeNums.push_back(v);
        v.clear();
      }
    } else if (i == 2) {
      for (int ii = 0; ii < 2; ii++) {
        v.push_back(StringToInt(s.substr(0, x[i])));
        if (ii == 0) {
          v.push_back(StringToInt(s.substr(x[i], x[1])));
          v.push_back(StringToInt(s.substr(x[i] + x[1], x[0])));
        } else {
          v.push_back(StringToInt(s.substr(x[i], x[0])));
          v.push_back(StringToInt(s.substr(x[i] + x[0], x[1])));
        }
        ThreeNums.push_back(v);
        v.clear();
      }
    } else if (i == 3) {
      for (int ii = 1; ii < s.size() - (x[0] + 1); ii++) {
        for (int iii = 1; iii < s.size() - ii; iii++) {
          v.push_back(StringToInt(s.substr(ii, iii)));
          v.push_back(StringToInt(s.substr(0, ii)));
          v.push_back(StringToInt(s.substr(ii + iii, s.size() - 1)));
          ThreeNums.push_back(v);
          v.clear();
        }
      }
    }
  }
}
long int TheRightNum(vector<vector<long long int> > ThreeNums, int x) {
  long int N = -1, sum = 0;
  for (int i = 0; i < ThreeNums.size(); i++) {
    for (int ii = 0; ii < x; ii++) {
      if (ThreeNums[i][ii] == -1) {
        sum = -1;
        break;
      }
      sum += ThreeNums[i][ii];
    }
    if (sum > N) {
      N = sum;
    }
    sum = 0;
  }
  return N;
}
void FindAllPossibleNumsctr1(string s, int x[2], vector<long long int> &v,
                             vector<vector<long long int> > &ThreeNums) {
  v.clear();
  for (int ii = 0; ii < 3; ii++) {
    if (ii == 0) {
      v.push_back(1000000);
      v.push_back(StringToInt(s.substr(0, x[0])));
      v.push_back(StringToInt(s.substr(x[0], s.size() - 1)));
      ThreeNums.push_back(v);
      v.clear();
    } else if (ii == 1) {
      v.push_back(1000000);
      v.push_back(StringToInt(s.substr(0, x[1])));
      v.push_back(StringToInt(s.substr(x[1], s.size() - 1)));
      ThreeNums.push_back(v);
      v.clear();
    } else {
      for (int ii = 1; ii < s.size() - (x[1] + 1); ii++) {
        for (int iii = 1; iii < s.size() - ii; iii++) {
          v.push_back(StringToInt(s.substr(ii, iii)));
          v.push_back(StringToInt(s.substr(0, ii)));
          v.push_back(StringToInt(s.substr(ii + iii, s.size() - 1)));
          ThreeNums.push_back(v);
          v.clear();
        }
      }
    }
  }
}
int main() {
  vector<vector<long long int> > ThreeNums;
  vector<long long int> v;
  string s, IfSSize8;
  cin >> s;
  IfSSize8 = s;
  int ctr = 0, sub[3] = {1, 1, 1}, sub2[2] = {1, 1}, sum = 0;
  for (; s.find("1000000") < 31;) {
    if (s.find("1000000") == 0 || s.find("1000000") == s.size() - 7 ||
        ctr == 0) {
      v.push_back(1000000);
    } else
      v.push_back(-1);
    ctr++;
    s.erase(s.find("1000000"), 7);
  }
  if (ctr == 0) {
    if (s.size() < 19) {
      for (int i = 0; i < 3; i++) {
        for (int ii = 1; sub[i] < 6 && sub[1] + sub[2] + sub[0] < s.size();)
          sub[i]++;
      }
      if (s.size() < 3) {
        cout << "-1";
      } else {
        FindAllPossibleNums(s, sub, v, ThreeNums);
        cout << TheRightNum(ThreeNums, 3);
      }
    } else {
      cout << "-1";
    }
  } else if (ctr == 2) {
    v.push_back(StringToInt(s));
    ThreeNums.push_back(v);
    cout << TheRightNum(ThreeNums, 3);
  }
  if (ctr == 1 && s.size() < 2) {
    sub[0] = 6, sub[1] = 1, sub[2] = 1;
    FindAllPossibleNums(IfSSize8, sub, v, ThreeNums);
    cout << TheRightNum(ThreeNums, 3);
  } else if (ctr == 3) {
    if (s.size() > 0) {
      cout << "-1";
    } else {
      ThreeNums.push_back(v);
      cout << TheRightNum(ThreeNums, 3);
    }
  } else if (ctr == 1) {
    if (IfSSize8.find("1000000") != 0 &&
        IfSSize8.find("1000000") != IfSSize8.size() - 7) {
      v.push_back(StringToInt(IfSSize8.substr(0, IfSSize8.find("1000000"))));
      v.push_back(StringToInt(
          IfSSize8.substr(IfSSize8.find("1000000") + 7, IfSSize8.size() - 1)));
      ThreeNums.push_back(v);
      cout << TheRightNum(ThreeNums, 3);
    } else if (s.size() > 12) {
      cout << "-1";
    } else {
      for (int ii = 0; ii < 2; ii++) {
        for (; sub2[0] + sub2[1] != s.size() && sub2[ii] != 6;) {
          sub2[ii] += 1;
        }
      }
      FindAllPossibleNumsctr1(s, sub2, v, ThreeNums);
      cout << TheRightNum(ThreeNums, 3);
    }
  }
  return 0;
}
