#include <bits/stdc++.h>
using namespace std;
int main() {
  string x;
  cin >> x;
  stack<char> st;
  string ans;
  vector<char> minn(x.size());
  minn[x.size() - 1] = x[x.size() - 1];
  for (int i = x.size() - 2; i >= 0; i--) {
    minn[i] = min(minn[i + 1], x[i]);
  }
  for (int i = 0; i < x.size(); i++) {
    while (!st.empty() && st.top() <= minn[i]) {
      ans.push_back(st.top());
      st.pop();
    }
    st.push(x[i]);
  }
  while (!st.empty()) {
    ans.push_back(st.top());
    st.pop();
  }
  cout << ans;
}
