#include <iostream> // This library is the basic in/out library
//#include <fstream> //This library will allow me to use files
#include <string> //This will allow me to use strings
#include <sstream>

using namespace std;

int main()
{
    //ifstream infile; //I am renaming the ifstream command to infile since it is easier to remember and us
    //ofstream outfile; //I also renamed the ofstream to outfile

    //infile.open("binary.txt"); //This is opening the binary.txt file which has to be located on the master directory
    istream &infile = cin;
    int numLength; //This will determine how many digits the binary number will have

    string line;
    while (getline(infile, line))
    {
        istringstream iss(line);
        iss >> numLength;

        int digit, binary = 0;

        for (int i = 0; i < numLength; i++)
        {
            iss >> digit;
            if (digit == 1)
                binary |= (1 << (numLength - i - 1));
        }

        cout << binary << endl;
    }

    return 0;
}