There are n beautiful skyscrapers in New York, the height of the i-th one is h_i. Today some villains have set on fire first n - 1 of them, and now the only safety building is n-th skyscraper.

Let's call a jump from i-th skyscraper to j-th (i < j) discrete, if all skyscrapers between are strictly lower or higher than both of them. Formally, jump is discrete, if i < j and one of the following conditions satisfied: 

  * i + 1 = j 
  * max(h_{i + 1}, …, h_{j - 1}) < min(h_i, h_j) 
  * max(h_i, h_j) < min(h_{i + 1}, …, h_{j - 1}). 



At the moment, Vasya is staying on the first skyscraper and wants to live a little longer, so his goal is to reach n-th skyscraper with minimal count of discrete jumps. Help him with calcualting this number.

Input

The first line contains a single integer n (2 ≤ n ≤ 3 ⋅ 10^5) — total amount of skyscrapers.

The second line contains n integers h_1, h_2, …, h_n (1 ≤ h_i ≤ 10^9) — heights of skyscrapers.

Output

Print single number k — minimal amount of discrete jumps. We can show that an answer always exists.

Examples

Input


5
1 3 1 4 5


Output


3

Input


4
4 2 2 4


Output


1

Input


2
1 1


Output


1

Input


5
100 1 100 1 100


Output


2

Note

In the first testcase, Vasya can jump in the following way: 1 → 2 → 4 → 5.

In the second and third testcases, we can reach last skyscraper in one jump.

Sequence of jumps in the fourth testcase: 1 → 3 → 5.
import java.io.*;
import java.lang.reflect.Array;
import java.util.*;

public class D {
    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 FastReader s = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);

    private static int[] rai(int n) {
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = s.nextInt();
        }
        return arr;
    }

    private static int[][] rai(int n, int m) {
        int[][] arr = new int[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                arr[i][j] = s.nextInt();
            }
        }
        return arr;
    }

    private static long[] ral(int n) {
        long[] arr = new long[n];
        for (int i = 0; i < n; i++) {
            arr[i] = s.nextLong();
        }
        return arr;
    }

    private static long[][] ral(int n, int m) {
        long[][] arr = new long[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                arr[i][j] = s.nextLong();
            }
        }
        return arr;
    }

    private static int ri() {
        return s.nextInt();
    }

    private static long rl() {
        return s.nextLong();
    }

    private static String rs() {
        return s.next();
    }

//    static int MOD=1000000007;

    static int MOD=998244353;
    static long[] createFact()
    {
        long[] arr=new long[100001];
        arr[1]=1;
        for(int i=2;i<=100000;i++)
        {
            arr[i]=arr[i-1]*i;
            arr[i]%=MOD;
        }
        return arr;
    }

    static int bsearch2(List<Point> list,long x)
    {
        int l=0,r=list.size()-1;
        while(l<=r)
        {
            int mid=(l+r)/2;
            if(list.get(mid).i>=x)
            {
                if(mid==0 || list.get(mid-1).i<x)
                {
                    return mid;
                }
                else
                {
                    r=mid-1;
                }
            }
            else {
                l=mid+1;
            }
        }
        return -1;
    }
    static int bsearch(List<Point> list,long y)
    {
        int l=0,r=list.size()-1;
        while(l<=r)
        {
            int mid=(l+r)/2;
            if(list.get(mid).j>=y)
            {
                if(mid==0 || list.get(mid-1).j<y)
                {
                    return mid;
                }
                else
                {
                    r=mid-1;
                }
            }
            else {
                l=mid+1;
            }
        }
        return -1;
    }

    static class Node
    {
        int val;
        int h;

        public Node(int val, int h) {
            this.val = val;
            this.h = h;
        }
    }

    static void dfs(HashSet<Integer>[] list,int[] dist,boolean[] vis)
    {
        List<Integer> queue=new ArrayList<>();
        dist[0]=0;
        vis[0]=true;
        queue.add(0);

        while(queue.size()>0)
        {
            int size=queue.size();
            for(int i=0;i<size;i++)
            {
                int node=queue.remove(0);
                for(int j:list[node])
                {
                    if(!vis[j] || dist[j]>dist[node]+1)
                    {
                        queue.add(j);
                        vis[j]=true;
                        dist[j]=dist[node]+1;
                    }
                }
            }
        }
    }
    public static void main(String[] args) {
        StringBuilder ans = new StringBuilder();
//        int t = ri();
        int t=1;
        while(t-- >0)
        {
            int n=ri();
            int[] arr=rai(n);

            HashSet<Integer>[] list=new HashSet[n];
            for(int i=0;i<n;i++)
            {
                list[i]=new HashSet<>();
            }
//            System.out.println(Arrays.toString(list));
            for(int j=0;j<2;j++)
            {
                Stack<Integer> stack=new Stack<>();
                for(int i=0;i<n;i++)
                {
                    while(!stack.empty() && arr[stack.peek()]<arr[i])
                    {
                        int ind=stack.pop();
//                        list[i].add(ind);
                        list[ind].add(i);
                    }

                    if(!stack.empty())
                    {
//                        list[i].add(stack.peek());
                        list[stack.peek()].add(i);
                        if(arr[stack.peek()]==arr[i])
                        {
                            stack.pop();
                        }
                    }
                    stack.push(i);
                }
//                System.out.println(Arrays.toString(list));
                for(int i=0;i<n;i++)
                {
                    arr[i]=-arr[i];
                }
            }
            int[] dist=new int[n];
            Arrays.fill(dist,Integer.MAX_VALUE);
            dist[0]=0;
            for(int i=0;i<n;i++)
            {
                for(int j:list[i])
                {
                    dist[j]=Math.min(dist[j],dist[i]+1);
                }
            }
            ans.append(dist[n-1]).append("\n");
//            Arrays.fill(dist,Integer.MAX_VALUE);
//            boolean[] vis=new boolean[n];
//            dfs(list,dist,vis);
//            ans.append(dist[n-1]).append("\n");


        }
//        while (t-- > 0) {
//            int n=ri();
//            int m=ri();
//            List<Point> robber=new ArrayList<>();
//            for(int i=0;i<n;i++)
//            {
//                robber.add(new Point(rl(),rl()));
//            }
//
//            List<Point> light=new ArrayList<>();
//            for(int i=0;i<m;i++)
//            {
//                light.add(new Point(rl(),rl()));
//            }
//
//            long res=Long.MAX_VALUE;
//
//
//
//            //sort by y
//            light.sort(new Comparator<Point>() {
//                @Override
//                public int compare(Point o1, Point o2) {
//                    return Long.compare(o1.j,o2.j);
//                }
//            });
////            for(Point p:light)
////            {
////                System.out.println(p.i+" "+p.j);
////
////            }
//            long[] x=new long[m];
//            for(int i=0;i<m;i++)
//            {
//                x[i]=light.get(i).i;
//            }
//
//            SparseMatrix sp=new SparseMatrix(x);
//            HashSet<String> set=new HashSet<>();
//
//            List<Point> list=new ArrayList<>();
//            for(int y=0;y<=1000000;y++)
//            {
//                int ind=bsearch(light,y);
//                if(ind==-1)
//                {
//                    if(!set.contains("0/"+y)) {
//                        list.add(new Point(0, y));
//                        set.add("0/"+y);
//                    }
//                    break;
//                }
//
//                long maxX=sp.getMax(ind,m-1);
//                if(!set.contains((maxX+1)+"/"+y)) {
//                    list.add(new Point(maxX + 1, y));
//                    set.add((maxX+1)+"/"+y);
//                }
////                System.out.println(y+" "+maxX);
//
//            }
//
//
//
//
//            //sort by x
//            light.sort(new Comparator<Point>() {
//                @Override
//                public int compare(Point o1, Point o2) {
//                    return Long.compare(o1.i,o2.i);
//                }
//            });
//            long[] y=new long[m];
//            for(int i=0;i<m;i++)
//            {
//                y[i]=light.get(i).j;
//            }
//
//            sp=new SparseMatrix(y);
//            for(int x1=0;x1<=1000000;x1++)
//            {
//                int ind=bsearch2(light,x1);
//                if(ind==-1)
//                {
//                    if(!set.contains(x1+"/0")) {
//                        list.add(new Point(x1, 0));
//                        set.add(x1+"/0");
//                    }
//                    break;
//                }
//
//                long maxY=sp.getMax(ind,m-1);
//
//                if(!set.contains(x1+"/"+(maxY+1))) {
//                    list.add(new Point(x1, maxY + 1));
//                    set.add(x1+"/"+(maxY+1));
//                }
//
//            }
//
//
//
////            List<Point> list2=new ArrayList<>(list);
////            list.sort(new Comparator<Point>() {
////                @Override
////                public int compare(Point o1, Point o2) {
////                    return Long.compare(o1.i,o2.i);
////                }
////            });
////
////            list2.sort(new Comparator<Point>() {
////                @Override
////                public int compare(Point o1, Point o2) {
////                    return Long.compare(o1.j,o2.j);
////                }
////            });
//
//            System.out.println(list);
//////            System.out.println(list2);
//
//            long resX=0,resY=0;
//
//            for(Point p:robber)
//            {
//
//                long currX=Long.MAX_VALUE;
//                long currY=Long.MAX_VALUE;
//                long dist=Long.MAX_VALUE;
//                for(Point l:list)
//                {
//                    long xDiff=Math.max(0,l.i-p.i);
//
//                    long yDiff=Math.max(0,l.j-p.j);
//                    if(xDiff+yDiff<dist)
//                    {
//                        dist=xDiff+yDiff;
//                        currX=xDiff;
//                        currY=yDiff;
//                    }
//                }
//                resX=Math.max(resX,currX);
//                resY=Math.max(resY,currY);
//
//            }
//            ans.append(resX+resY).append("\n");
//
//
//
//        }
        out.print(ans.toString());
        out.flush();

    }

    static class Point
    {
        long i,j;

        public Point(long i, long j) {
            this.i = i;
            this.j = j;
        }

        @Override
        public String toString() {
            return "("+this.i+" "+this.j+")";
        }
    }

    static public class SparseMatrix {
        private long[] arr;
        private int m;
//        private int[][] minSparse;
//        private int[][] minIndex;
        private long[][] maxSparse;
        private int[][] maxIndex;
        private int n;
        public SparseMatrix(long[] arr) {
            this.arr = arr;
            this.m=arr.length;
            this.n=Integer.toBinaryString(m).length();
//            minSparse=new int[n][m];
//            minIndex=new int[n][m];

            maxSparse=new long[n][m];
            maxIndex=new int[n][m];
//        for(int i=0;i<n;i++)
//        {
//            Arrays.fill(minSparse[i],-1);
//        }
//        for(int i=0;i<n;i++)
//        {
//            Arrays.fill(minIndex[i],-1);
//        }

//            createMinSparse();
            createMaxSparse();
        }
        private void createMaxSparse()
        {
            for(int j=0;j<m;j++)
            {
                maxSparse[0][j]=arr[j];
                maxIndex[0][j]=j;
            }
            for(int i=1;i<n;i++)
            {
                for(int j=0;j+(1<<(i-1))<m;j++)
                {
                    long left=maxSparse[i-1][j];
                    long right=maxSparse[i-1][j+(1<<(i-1))];
                    maxSparse[i][j]=Math.max(left,right);

                    if(left>=right)
                    {
                        maxIndex[i][j]=maxIndex[i-1][j];
                    }
                    else
                    {
                        maxIndex[i][j]=maxIndex[i-1][j+(1<<(i-1))];
                    }
                }
            }
        }
//        private void createMinSparse()
//        {
//            //filling the first row of sparse matrix with the values of the input array
//            for(int j=0;j<m;j++)
//            {
//                minSparse[0][j]=arr[j];
//                minIndex[0][j]=j;
//            }
//            //filling other rows of the sparse matrix
//            for(int i=1;i<n;i++)
//            {
//                for(int j=0;j+(1<<(i-1))<m;j++)
//                {
//
//                    int left=minSparse[i-1][j];
//                    int right=minSparse[i-1][j+(1<<(i-1))];
//
//                    //change to min-> max to create MaxSparseMatrix
//                    minSparse[i][j]=Math.min(left,right);
//
//                    //filling index
//                    if(left<=right)
//                    {
//                        minIndex[i][j]=minIndex[i-1][j];
//                    }
//                    else {
//                        minIndex[i][j]=minIndex[i-1][j+(1<<(i-1))];
//                    }
//
//                }
//            }
//        }

        //get minimum value in range l->r inclusive
    /*
        for any range [l, r] we can find the two values and
        find their minimum. These values are defined below:

        len: length of the required range, i.e., r-l+1

        p: maximum power of 2 that can fit in len. E.g, [1,11] , len=11, thus p=3

        k: 2^p

        find the minimum between sparse[p][l] and sparse[p][r-k+1]
    */
//        public int getMin(int l,int r)
//        {
//            int len=r-l+1;
//            int p=Integer.toBinaryString(len).length()-1;
//            int k=1<<p;
//
//            int left=minSparse[p][l];
//            int right=minSparse[p][r-k+1];
//            return Math.min(right,left);
//        }
//
//        public int getMinIndex(int l,int r)
//        {
//            int len=r-l+1;
//            int p=Integer.toBinaryString(len).length()-1;
//            int k=1<<p;
//
//            int left=minSparse[p][l];
//            int right=minSparse[p][r-k+1];
//            if (left <= right) {
//                return minIndex[p][l];
//            } else {
//                return minIndex[p][r - k + 1];
//            }
//        }


        public long getMax(int l,int r)
        {
            int len=r-l+1;
            int p=Integer.toBinaryString(len).length()-1;
            int k=1<<p;

            long left=maxSparse[p][l];
            long right=maxSparse[p][r-k+1];
            return Math.max(right,left);
        }

        public int getMaxIndex(int l,int r)
        {
            int len=r-l+1;
            int p=Integer.toBinaryString(len).length()-1;
            int k=1<<p;
            long left=maxSparse[p][l];
            long right=maxSparse[p][r-k+1];
            if(left>=right)
            {
                return maxIndex[p][l];

            }
            return maxIndex[p][r-k+1];
        }
//        void print()
//        {
//            for(int i=0;i<minSparse.length;i++)
//            {
//                for(int j=0;j<minSparse[i].length;j++)
//                {
//                    System.out.print(minSparse[i][j]+" ");
//                }
//                System.out.println();
//            }
//            System.out.println();
//            for(int i=0;i<n;i++)
//            {
//                for(int j=0;j<m;j++)
//                {
//                    System.out.print(minIndex[i][j]+" ");
//                }
//                System.out.println();
//            }
//        }
    }


}
