#include <iostream>
#include <cmath>
using namespace std;
int na10(string dana) {
int pom = 0;
int dl = dana.length();
for (int i = 0; i < dl; i++){
int x = int(dana[dl-i-1]) - 48;
pom = pom + x * pow(8, i);
}
return pom;
}
int main() {
cout << na10("174") << endl;
cout << na10("362373") << endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y21hdGg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgbmExMChzdHJpbmcgZGFuYSkgewogICAgaW50IHBvbSA9IDA7CiAgICBpbnQgZGwgPSBkYW5hLmxlbmd0aCgpOwogICAgZm9yIChpbnQgaSA9IDA7IGkgPCBkbDsgaSsrKXsKICAgICAgICBpbnQgeCA9IGludChkYW5hW2RsLWktMV0pIC0gNDg7CiAgICAgICAgcG9tID0gcG9tICsgeCAqIHBvdyg4LCBpKTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHBvbTsKfQoKaW50IG1haW4oKSB7CiAgICBjb3V0IDw8IG5hMTAoIjE3NCIpIDw8IGVuZGw7CiAgICBjb3V0IDw8IG5hMTAoIjM2MjM3MyIpIDw8IGVuZGw7CiAgICByZXR1cm4gMDsKfQo=