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;
class pii {
 public:
  int first, second;
  pii() { first = second = 0; }
  pii(int _first, int _second) {
    first = _first;
    second = _second;
  }
  bool operator<(const pii &a) const {
    if (first != a.first) {
      return first < a.first;
    }
    return second < a.second;
  }
};
int main() {
  char s[101010];
  int n;
  scanf("%s", s);
  n = strlen(s);
  pii a[101010];
  a[n - 1] = pii(s[n - 1], n - 1);
  int i;
  for (i = n - 2; i >= 0; i--) {
    a[i] = pii(s[i], i);
    a[i] = min(a[i], a[i + 1]);
  }
  pii cur = a[0];
  char buf[101010];
  int buf_size = 0;
  char u[101010];
  int l = 0;
  bool d[101010] = {false};
  i = 0;
  while (cur.first != -1) {
    for (; i < cur.second; i++) {
      if (!d[i]) {
        d[i] = true;
        buf[buf_size++] = s[i];
      }
    }
    u[l++] = cur.first;
    d[cur.second] = true;
    if (cur.second != n - 1) {
      pii nxt = a[cur.second + 1];
      while (buf_size && buf[buf_size - 1] <= nxt.first) {
        u[l++] = buf[--buf_size];
      }
      cur = nxt;
    } else {
      cur.first = -1;
    }
  }
  while (buf_size) {
    u[l++] = buf[--buf_size];
  }
  u[n] = '\0';
  printf("%s\n", u);
  return 0;
}
