#include<iostream>
#include<string>
#include<sstream>
#include<vector>
using namespace std;
void solveMethod(string line)
{
stringstream ss(line);
string temp;
vector<string> vect;
int count = 0;
while(getline(ss, temp, '#'))
{
for(int i = 0; i < temp.size(); i++)
{
if(temp[i] < '0' || temp[i] > '9')
{
cout << "invalid IP";
return;
}
}
vect.push_back(temp);
}
if(vect.size() != 4)
{
cout << "invalid IP" << endl;
return;
}
else
{
for(int i = 0; i < 4; i++)
{
int data = stoi(vect[i]);
if(i == 0)
{
if(data < 1 || data > 128)
{
cout << "invalid IP" << endl;
return;
}
}
else
{
if(data < 0 || data > 255)
{
cout << "invalid IP" << endl;
return;
}
}
count += data << 8 * (3 - i);
}
}
cout << count << endl;
}
int main()
{
string s;
getline(cin, s);
solveMethod(s);
return 0;
}