#include <iostream>
using namespace std;

int main () {

int a[20]={0}, b[20]={0}, k = 0;
int train = 0, zero = 0;

    for (int i = 0; i < 20; i++){
        cin >> a[i];

    if (a[i] != 0)
        train++;
        else zero++;

    if (train == zero)
        i=100;

    }


    for (int j = 1; j < 20; j++){


            if (a[j-1] != 0 && a[j] == 0){
                b[k] = a[j-1];
                k++;

                for (int count = j; count < 19; count++)
                a[count-1] = a[count+1];

                j = 0;

            }

        }

    for (int n = 0; n < 20; n++) {
        if (b[n] != 0)
        cout << b[n] << endl;

    }

    return 0;

}