#include <bits/stdc++.h>
using namespace std;
int n, i, j;
string s, t, u, v;
int main() {
  cin >> s;
  n = s.size();
  for (t = v = s, i = n - 2; i >= 0; i--) v[i] = min(s[i], v[i + 1]);
  for (i = 0; i < n; i++) {
    for (; j && v[i] >= t[j - 1];) u += t[--j];
    if (s[i] == v[i])
      u += s[i];
    else
      t[j++] = s[i];
  }
  for (; j;) u += t[--j];
  cout << u;
}
