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;
template <class T>
void show(const vector<T> &a) {
  for (T x : a) cout << x << " ";
  cout << '\n';
}
const long long N = 2e5 + 50, oo = 1e18 + 500;
const long long mod = 998244353;
const long double eps = 1e-12, PI = 2 * acos(0.0);
long long n, m, k;
long long cnt = 0;
vector<vector<long long>> g[N];
vector<long long> visit(N, 0);
signed main() {
  ios::sync_with_stdio(0);
  cout.tie(0);
  cin.tie(0);
  string s;
  cin >> s;
  vector<set<long long>> ind(26);
  n = ((long long)(s.size()));
  for (long long i = 0; i < n; i++) {
    long long x = s[i] - 'a';
    ind[x].insert(i);
  }
  long long cur = -1;
  long long m = n;
  while (m) {
    long long nxt = -1;
    for (long long i = 0; i < 26; i++) {
      if (((long long)(ind[i].size()))) {
        auto it = ind[i].upper_bound(cur);
        if (it != ind[i].end()) {
          nxt = *it;
          break;
        }
      }
    }
    long long prev = -1;
    for (long long i = 0; i < 26; i++) {
      if (((long long)(ind[i].size()))) {
        auto it = ind[i].lower_bound(cur);
        if (it != ind[i].begin()) {
          it--;
          prev = max(prev, *it);
          ;
        }
      }
    }
    m--;
    if (prev == -1) {
      cout << s[nxt];
      long long x = s[nxt] - 'a';
      ind[x].erase(nxt);
      cur = nxt;
      continue;
    }
    if (nxt == -1) {
      cout << s[prev];
      long long x = s[prev] - 'a';
      ind[x].erase(prev);
      cur = prev;
      continue;
    }
    if (s[prev] <= s[nxt]) {
      cout << s[prev];
      long long x = s[prev] - 'a';
      ind[x].erase(prev);
      cur = prev;
    } else {
      cout << s[nxt];
      long long x = s[nxt] - 'a';
      ind[x].erase(nxt);
      cur = nxt;
    }
  }
}
