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 int mod = 1000000007;
vector<long long int> primes;
void Sieve(long long int n) {
  bool prime[n + 1];
  for (long long int i = 0; i < n + 1; ++i) prime[i] = true;
  for (long long int p = 2; p * p <= n; ++p) {
    if (prime[p] == true) {
      for (long long int i = 2 * p; i <= n; i += p) prime[i] = false;
    }
  }
  for (long long int p = 2; p <= n; p++)
    if (prime[p]) primes.push_back(p);
}
long long int gcd(long long int a, long long int b) {
  if (b > a) swap(a, b);
  if (a % b == 0)
    return b;
  else
    return gcd(a % b, b);
}
long long int lcm(long long int a, long long int b) {
  return (a * b) / gcd(a, b);
}
long long int power(long long int x, long long int y, long long int m) {
  long long int res = 1;
  x = x % m;
  while (y > 0) {
    if (y % 2 == 1) res = (res * x) % m;
    y = y / 2;
    x = (x * x) % m;
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string s;
  cin >> s;
  long long int arr[26] = {0};
  for (long long int i = 0; i < s.length(); ++i) {
    arr[s[i] - 97]++;
  }
  stack<char> st;
  vector<char> ans;
  char small;
  for (long long int i = 0; i < s.length(); ++i) {
    long long int flag = 0;
    for (long long int j = 26; j >= 0; --j) {
      if (arr[j]) {
        small = (char)(j + 97);
      }
    }
    while (!st.empty() && st.top() <= small) {
      ans.push_back(st.top());
      st.pop();
    }
    st.push(s[i]);
    arr[s[i] - 97]--;
  }
  while (!st.empty()) {
    char to = st.top();
    ans.push_back(to);
    st.pop();
  }
  for (char c : ans) cout << c;
}
