#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
#define fi first
#define se second
const ll N = 1e6+9, mod = 998244353;

void solve() {
    stack<ll>a;
    ll x;
    while (cin >> x) {
        if (x != 0)
            a.push(x);
    }
    while (!a.empty() ) {
        cout << a.top() << " ";
        a.pop();
    }
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int T = 1;
    //cin >> T;
    while (T--)
        solve();
    return 0;
}