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
import java.util.*;
import java.io.*;
import static java.lang.Math.*;
public class MainS {
    static final long MOD = 1_000_000_007, INF = 1_000_000_000_000_000_000L;
    static final int INf = 1_000_000_000;
    static FastReader reader;
    static PrintWriter writer;

    public static void main(String[] args) {
        Thread t = new Thread(null, new O(), "Integer.MAX_VALUE", 100000000);
        t.start();
    }

    static class O implements Runnable {
        public void run() {
            try {
                magic();
            } catch (Exception e) {
                e.printStackTrace();
                System.exit(1);
            }
        }
    }

    public 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;
        }

    }

    static void magic() throws IOException {
        reader = new FastReader();
        writer = new PrintWriter(System.out, true);
        String s = reader.next();
        int n = s.length();
        TreeMap<Character, Integer> tm = new TreeMap<>();
        Stack<Character> st = new Stack<>();
        int idx = 0;
        for(int i=0;i<n;++i) {
            add(tm, s.charAt(i));
        }
        while(!st.isEmpty() || !tm.isEmpty()) {
           if(tm.isEmpty()) {
               while(!st.isEmpty()) {
                   writer.print(st.pop());
               }
           }
           else if(st.isEmpty() || st.peek()>tm.firstKey()) {
               char c = s.charAt(idx++);
               st.add(c);
               remove(tm, c);
           }
           else {
               writer.print(st.pop());
           }
        }
        writer.println();
    }
    static void add(TreeMap<Character, Integer> tm, char c) {
        Integer val = tm.get(c);
        if(val==null) {
            val = 0;
        }
        tm.put(c, val+1);
    }
    static void remove(TreeMap<Character, Integer> tm, char c) {
        Integer val = tm.get(c);
        if(val==1) {
            tm.remove(c);
        }
        else {
            tm.put(c, val-1);
        }
    }
}