#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  multiset<char> ms;
  for (char c : s) ms.insert(c);
  string t, u;
  for (int i = 0; i < (s.size()); i++) {
    ms.erase(ms.find(s[i]));
    t += s[i];
    while (!t.empty() && ms.lower_bound(t.back()) == ms.begin()) {
      u += t.back();
      t.pop_back();
    }
  }
  cout << u << endl;
}
