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;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T>
void __print(const T &x) {
  int f = 0;
  cerr << '{';
  for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
struct _ {
  ios_base::Init i;
  _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); }
} _;
int dx[] = {-1, 0, 1, 0, -1, -1, 1, 1};
int dy[] = {0, 1, 0, -1, -1, 1, 1, -1};
int main() {
  string s;
  cin >> s;
  int n = s.length();
  string t, u;
  vector<set<int>> v(26);
  for (int i = 0; i <= n - 1; i++) v[s[i] - 'a'].insert(i);
  int nxt = 0;
  for (int j = 0; j <= 25; j++) {
    if (v[j].empty() == false) {
      nxt = *v[j].begin();
      break;
    }
  }
  for (int i = 0; i <= n - 1; i++) {
    if (i == nxt) {
      u.push_back(s[i]);
      for (int j = (s[i] - 'a'); j <= 25; j++) {
        auto it = v[j].upper_bound(i);
        if (it != v[j].end()) {
          nxt = *it;
          break;
        }
      }
      if (i == nxt) {
        break;
      }
      while (!t.empty() and t.back() <= s[nxt])
        u.push_back(t.back()), t.pop_back();
    } else {
      t.push_back(s[i]);
    }
  }
  s.push_back((char)('z' + 1));
  for (int i = nxt + 1; i <= n; i++) {
    while (!t.empty() and t.back() < s[i]) u.push_back(t.back()), t.pop_back();
    t.push_back(s[i]);
  }
  cout << u;
  return 0;
}
