Petya recieved a gift of a string s with length up to 105 characters for his birthday. He took two more empty strings t and u and decided to play a game. This game has two possible moves:

  * Extract the first character of s and append t with this character. 
  * Extract the last character of t and append u with this character. 



Petya wants to get strings s and t empty and string u lexicographically minimal.

You should write a program that will help Petya win the game.

Input

First line contains non-empty string s (1 ≤ |s| ≤ 105), consisting of lowercase English letters.

Output

Print resulting string u.

Examples

Input

cab


Output

abc


Input

acdb


Output

abdc
#include <bits/stdc++.h>
using namespace std;
long long mypow(long long a, long long b) {
  if (b == 0) return 1;
  long long temp = mypow(a, b / 2);
  temp = (temp * temp) % 1000000007LL;
  if (b % 2 == 1) temp = (a * temp) % 1000000007LL;
  return temp;
}
int mygcd(int a, int b) {
  if (b == 0) return a;
  return mygcd(b, a % b);
}
int cntBits(long long a) {
  int ret = 0;
  while (a > 0) {
    ret++;
    a /= 2;
  }
  return ret;
}
stack<int> stk;
int main() {
  ios::sync_with_stdio(0);
  int tt = 1, tcase;
  for (tcase = 1; tcase <= tt; tcase++) {
    vector<char> ans;
    ans.clear();
    string s;
    cin >> s;
    int i, arr[s.size() + 1];
    arr[s.size() - 1] = s.size() - 1;
    for (i = s.size() - 2; i >= 0; i--) {
      if (s[i] >= s[arr[i + 1]])
        arr[i] = arr[i + 1];
      else
        arr[i] = i;
    }
    for (i = 0; i <= s.size() - 1; i++) {
      if (stk.empty())
        stk.push(i);
      else {
        while (!stk.empty() && s[stk.top()] <= s[arr[i]]) {
          ans.push_back(s[stk.top()]);
          stk.pop();
        }
        stk.push(i);
      }
    }
    while (!stk.empty()) {
      ans.push_back(s[stk.top()]);
      stk.pop();
    }
    for (i = 0; i <= ans.size() - 1; i++) cout << ans[i];
    cout << endl;
  }
  return 0;
}
