#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, u;
  vector<char> t;
  cin >> s;
  int i, j, prev = 0;
  vector<int> v(27, -1);
  for (i = 0; i < s.length(); ++i) {
    int x = s[i] - 'a';
    v[x] = i;
  }
  i = 0;
  j = 0;
  while (true) {
    while (i < 26 && v[i] < prev && v[i] == -1) i++;
    prev = v[i];
    if (i == 26)
      break;
    else {
      int x = t.size() - 1;
      while (x >= 0 && t[x] - 'a' <= i) {
        u += t[x];
        t.pop_back();
        x--;
      }
      while (j <= v[i]) {
        x = s[j] - 'a';
        if (x == i)
          u += s[j];
        else
          t.push_back(s[j]);
        j++;
      }
      i++;
    }
  }
  reverse(t.begin(), t.end());
  cout << u;
  for (i = 0; i < t.size(); ++i) {
    cout << t[i];
  }
  return 0;
}
