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


//@author->.....future_me......//

//..............Learning.........//

import java.util.*;
import java.io.*;
import java.lang.*;
import java.math.BigInteger;

public class A {

//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Fast IO <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< //

  static class FastReader {
    BufferedReader  br;
    StringTokenizer st;

    public FastReader() {
      br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
      while (st == null || !st.hasMoreElements()) {
        try {
          st = new StringTokenizer(br.readLine());
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
      return st.nextToken();
    }

    int nextInt() {
      return Integer.parseInt(next());
    }

    long nextLong() {
      return Long.parseLong(next());
    }

    double nextDouble() {
      return Double.parseDouble(next());
    }

    String nextLine() {
      String str = "";
      try {
        str = br.readLine();
      } catch (IOException e) {
        e.printStackTrace();
      }
      return str;
    }
  }

//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Code Starts <<<<<<<<<<<<<<<<<<<<<<<<<<<<< //
  static FastReader  sc  = new FastReader();
  static PrintWriter out = new PrintWriter(System.out);

  public static void main(String[] args) throws Exception {
//    try {
//      int t = sc.nextInt();
//      while (t-- > 0)
    A.go();
    out.flush();
//    } catch (Exception e) {
//      return;
//    }
  }

  static void go() throws Exception {
    String s = sc.next();
    int n = s.length();
    int freq[] = new int[26];
    for (int i = 0; i < n; i++) {
      freq[s.charAt(i) - 'a']++;
    }
    StringBuilder t = new StringBuilder("");
    StringBuilder ans = new StringBuilder("");
    int fr[] = new int[26];
    for (char i = 'a'; i <= 'z'; i++) {
      int temp = s.lastIndexOf(i);

      if (s.length() > 0 && t.length() > 0 && t.charAt(t.length() - 1) <= i) {
        int j = t.length() - 1;
        while (j >= 0 && t.charAt(j) <= i) {
          ans.append(t.charAt(j));

          j--;
        }
        if (j >= 0) {

          t.delete(j + 1, t.length());
        } else {
          t.delete(0, t.length());

        }
      }

      if (temp != -1) {
        if (freq[i - 'a'] > 0) {

          while (temp != -1 && freq[i - 'a'] > 0) {
            ans.append(i);
            freq[i - 'a']--;
          }
          for (int j = 0; j <= temp; j++) {
            if (s.charAt(j) != i) {
              t.append(s.charAt(j));
            }
          }

          String ss = s.substring(temp + 1, s.length());
          s = ss;

          freq = new int[26];
          for (int j = 0; j < s.length(); j++) {
            freq[s.charAt(j) - 'a']++;
          }
          if (s.length() == 0) {
            break;
          }

        }
      }
    }
//    System.out.println(ans + "-- " + s + "-- " + t);

    for (int i = t.length() - 1; i >= 0; i--) {

      ans.append(t.charAt(i));
    }
    System.out.println(ans);
  }

  static long x, y;

  static long gcdExtended(int a, int b) {
    // Base Case
    if (b == 0) {
      x = 1;
      y = 0;
      return a;
    }

    // To store results of recursive call

    long d = gcdExtended(b, a % b);
    long x1 = x;
    long y1 = y;
    // Update x and y using results of recursive
    // call
    x = y1;
    y = x1 - (a / b) * y1;

    return d;
  }
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Code Ends <<<<<<<<<<<<<<<<<<<<<<<<<<<<< //

  static BigInteger gcd(BigInteger a, BigInteger b) {
    if (a.equals(BigInteger.ZERO)) {
      return b;
    }
    return gcd(b.mod(a), a);
  }

  static long gcd(long a, long b) {
    if (a == 0) {
      return b;
    }
    return gcd(b % a, a);
  }

  static void sort(long[] a) {
    ArrayList<Long> aa = new ArrayList<>();
    for (Long i : a) {
      aa.add(i);
    }
    Collections.sort(aa);
    for (int i = 0; i < a.length; i++)
      a[i] = aa.get(i);
  }

  static int mod = 3;

  static long pow(long x, long y) {
    long res = 1l;
    while (y != 0) {
      if (y % 2 == 1) {
        res = (x * res) % mod;
        ;
      }
      y /= 2;
      x = (x * x) % mod;
    }
    return res;
  }

}

class dsu {
  int par[];
  int ranks[];

  dsu(int n) {
    par = new int[n];
    ranks = new int[n];
    for (int i = 0; i < n; i++) {
      par[i] = i;
    }
  }

  int find(int x) {
    if (par[x] == x) {
      return x;
    }
    return find(par[x]);
  }

  boolean unite(int x, int y) {
    int xx = find(x);
    int yy = find(y);
    if (xx == yy) {
      return false;
    }

    if (ranks[xx] < ranks[yy])
      par[xx] = yy;

    else if (ranks[yy] < ranks[xx])
      par[yy] = xx;

    else {
      par[yy] = xx;

      ranks[xx]++;
    }
    return true;

  }
}

//..............Learning.........//

//@author->.....future_me......//

//..............Learning.........//
