#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int n = s.length();
  vector<int> a(n);
  a[n - 1] = s[n - 1];
  for (int i = n - 2; i >= 0; i--) a[i] = min((int)s[i], a[i + 1]);
  stack<char> t;
  string u = "";
  for (int i = 0; i < n; i++) {
    while (!t.empty() && t.top() <= a[i]) {
      u += t.top();
      t.pop();
    }
    t.push(s[i]);
  }
  while (!t.empty()) {
    u += t.top();
    t.pop();
  }
  cout << u << endl;
  return 0;
}
