#include <iostream>
using namespace std;
int atoi(const char *str) {
long long val = 0;
const long long limit = 2147483647;
bool isNegative = false;
while (*str != '\0' && *str == ' ') ++str;
if (*str == '\0') return val;
if (*str == '-') {
isNegative = true;
++str;
} else if (*str == '+') {
isNegative = false;
++str;
}
while (*str != '\0') {
char c = *str;
if (c < '0' || c > '9') {
break;
}
val = val*10 + (c-'0');
if (val > limit) break;
++str;
}
if (val > limit) {
if (isNegative) {
return (-limit-1);
} else {
return limit;
}
}
if (isNegative) val = -val;
return val;
}
int main(int argc, char const *argv[]) {
char a[] = "2147483648";
cout << atoi(a) << endl;
return 0;
}