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.io.IOException;
import java.util.*;



//import javafx.util.Pair; 
//import java.util.concurrent.LinkedBlockingDeque;







    
  public class Codeforces {
     
        
        public static long mod = (long)Math.pow(10,9)+7 ;
        public static double epsilon=0.00000000008854;//value of epsilon
        public static InputReader sc = new InputReader(System.in);
        public static PrintWriter pw = new PrintWriter(System.out);
        
        
        public static int gcd(int a,int b){
            while(b>0){
                int t=b;
                b=a%b;
                a=t;
            }
            return a;
        }
        
	public static int[] nextGreaterElementIndexL(long a[]){//right to left
		int n=a.length;
		Stack<Integer> st=new Stack<>();
		int ans[]=new int [n];
		Arrays.fill(ans, -1);
		st.push(n-1);
		for(int i=n-2;i>=0;i--){
			while(!st.empty()&&a[st.peek()]<=a[i]){
				int in=st.pop();
				ans[in]=i;
			}
			st.push(i);
		}
		return ans;
    }
    public static int[] nextSmallerElementIndexL(long a[]){//right to left
		int n=a.length;
		Stack<Integer> st=new Stack<>();
		int ans[]=new int [n];
		Arrays.fill(ans, -1);
		st.push(n-1);
		for(int i=n-2;i>=0;i--){
			while(!st.empty()&&a[st.peek()]>=a[i]){
				int in=st.pop();
				ans[in]=i;
			}
			st.push(i);
		}
		return ans;
    }
    public static int solve(long a[]){
        int n=a.length;
        int dp[]=new int[n];
        for(int i=1;i<n;i++){
            dp[i]=i;
            for(int j=i-1;j>=0;j--){
                if(a[j]>=a[i]){
                    dp[i]=Math.min(1+dp[j], dp[i]);
                    break;
                }
            }
            for(int j=i-1;j>=0;j--){
                if(a[j]<=a[i]){
                    dp[i]=Math.min(1+dp[j], dp[i]);
                    break;
                }
            }
            

        }
        return dp[n-1];

    }
    public static int [] nextGreaterElementIndexR(long a[]){///left to right
		int n=a.length;
        Stack<Integer> st=new Stack<>();
		int ans[]=new int [n];
		Arrays.fill(ans, n);
		st.push(0);
		for(int i=1;i<n;i++){
			while(!st.empty()&&a[st.peek()]<=a[i]){
				int in=st.pop();
				ans[in]=i;
			}
			st.push(i);
		}
		return ans;
    }
    public static int [] nextGsmallerrElementIndexR(long a[]){///left to right
		int n=a.length;
        Stack<Integer> st=new Stack<>();
		int ans[]=new int [n];
		Arrays.fill(ans, n);
		st.push(0);
		for(int i=1;i<n;i++){
			while(!st.empty()&&a[st.peek()]>=a[i]){
				int in=st.pop();
				ans[in]=i;
			}
			st.push(i);
		}
		return ans;
	}
        public static void main(String[] args) {
            // code starts..
            
                int n=sc.nextInt();
                long a[]=scanLongArray(n);
                int left1[]=nextGreaterElementIndexL(a);
                //pw.println(left1);
                int left2[]=nextSmallerElementIndexL(a);
                int right1[]=nextGsmallerrElementIndexR(a);
                int right2[]=nextGreaterElementIndexR(a);
                //pw.println(left2);
                //int min=0;int max=0;
                int dp[]=new int[n];
                dp[0]=0;
                for(int i=0;i<n;i++)dp[i]=i;
                for(int i=0;i<n;i++){
                   
                   if(left1[i]!=-1){
                       dp[i]=Math.min(dp[left1[i]]+1, dp[i]);
                   } 
                   if(left2[i]!=-1){
                    dp[i]=Math.min(dp[left2[i]]+1, dp[i]);
                   }
                   //dp[i]=Math.min(dp[i], min);
                   if(i>0){
                       dp[i]=Math.min(dp[i-1]+1, dp[i]);
                   }
                   if(right1[i]!=n){
                       dp[right1[i]]=Math.min(dp[right1[i]], dp[i]+1);
                   }
                   if(right2[i]!=n){
                    dp[right2[i]]=Math.min(dp[right2[i]], dp[i]+1);
                }
                }
                pw.println(dp[n-1]);
                
            
            // Code ends...
            pw.flush();
            pw.close();
        }
       
        public static Comparator<Long[]> column(int i){
            return 
            new Comparator<Long[]>() {
                @Override
                public int compare(Long[] o1, Long[] o2) {
                    return o1[i].compareTo(o2[i]);//for ascending
                    //return o2[i].compareTo(o1[i]);//for descending
                }
            };
        }
        public static Comparator<Integer[]> col(int i){
            return 
            new Comparator<Integer[]>() {
                @Override
                public int compare(Integer[] o1, Integer[] o2) {
                    return o1[i].compareTo(o2[i]);//for ascending
                    //return o2[i].compareTo(o1[i]);//for descending
                }
            };
        }
        public static Comparator<Integer> des(){
            return 
            new Comparator<Integer>() {
                @Override
                public int compare(Integer o1, Integer o2) {
                    //return o1[i].compareTo(o2[i]);//for ascending
                    return o2.compareTo(o1);//for descending
                }
            };
        }
        
        
        
        
        public static String reverseString(String s){
            StringBuilder input1 = new StringBuilder(); 
            input1.append(s);  
            input1 = input1.reverse();
            return input1.toString();
        }
        public static int[] scanArray(int n){
            int a[]=new int [n];
            for(int i=0;i<n;i++)
            a[i]=sc.nextInt();
    
            return a;
        }
        public static long[] scanLongArray(int n){
            long a[]=new long [n];
            for(int i=0;i<n;i++)
            a[i]=sc.nextLong();
    
            return a;
        }
        public static String [] scanStrings(int n){
            String a[]=new String [n];
            for(int i=0;i<n;i++)
            a[i]=sc.nextLine();
    
            return a;
        }
        public static class InputReader {
    
            private final InputStream stream;
            private final byte[] buf = new byte[8192];
            private int curChar, snumChars;
            private SpaceCharFilter filter;
    
            public InputReader(InputStream stream) {
                this.stream = stream;
            }
    
            public int snext() {
                if (snumChars == -1)
                    throw new InputMismatchException();
                if (curChar >= snumChars) {
                    curChar = 0;
                    try {
                        snumChars = stream.read(buf);
                    } catch (IOException e) {
                        throw new InputMismatchException();
                    }
                    if (snumChars <= 0)
                        return -1;
                }
                return buf[curChar++];
            }
    
            public int nextInt() {
                int c = snext();
                while (isSpaceChar(c)) {
                    c = snext();
                }
                int sgn = 1;
                if (c == '-') {
                    sgn = -1;
                    c = snext();
                }
                int res = 0;
                do {
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    res *= 10;
                    res += c - '0';
                    c = snext();
                } while (!isSpaceChar(c));
                return res * sgn;
            }
    
            public long nextLong() {
                int c = snext();
                while (isSpaceChar(c)) {
                    c = snext();
                }
                int sgn = 1;
                if (c == '-') {
                    sgn = -1;
                    c = snext();
                }
                long res = 0;
                do {
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    res *= 10;
                    res += c - '0';
                    c = snext();
                } while (!isSpaceChar(c));
                return res * sgn;
            }
    
            public int[] nextIntArray(int n) {
                int a[] = new int[n];
                for (int i = 0; i < n; i++) {
                    a[i] = nextInt();
                }
                return a;
            }
    
            public String readString() {
                int c = snext();
                while (isSpaceChar(c)) {
                    c = snext();
                }
                StringBuilder res = new StringBuilder();
                do {
                    res.appendCodePoint(c);
                    c = snext();
                } while (!isSpaceChar(c));
                return res.toString();
            }
    
            public String nextLine() {
                int c = snext();
                while (isSpaceChar(c))
                    c = snext();
                StringBuilder res = new StringBuilder();
                do {
                    res.appendCodePoint(c);
                    c = snext();
                } while (!isEndOfLine(c));
                return res.toString();
            }
    
            public boolean isSpaceChar(int c) {
                if (filter != null)
                    return filter.isSpaceChar(c);
                return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
            }
    
            private boolean isEndOfLine(int c) {
                return c == '\n' || c == '\r' || c == -1;
            }
    
            public interface SpaceCharFilter {
                public boolean isSpaceChar(int ch);
            }
        }
        
    }
    class SegmentTree{
    int s[],n;
    
    int li[];
    long qn[];
	SegmentTree(int a[],long q[]){
        n=a.length;
        qn=q;
        li=a;
		int l=(int)Math.ceil(Math.log(n)/Math.log(2));
		l=2*(int)Math.pow(2,l)-1;
		s=new int[l];
		createSegmentTreeUtil(a, 0, 0, a.length-1);
	}
	
	int createSegmentTreeUtil(int a[],int root,int l,int r){
		if(l==r)
		s[root]=l;
		else
		s[root]= Compare(createSegmentTreeUtil(a, 2*root+1, l, (l+r)/2), createSegmentTreeUtil(a,2*root+2, (l+r)/2+1,r));
		return s[root];
	}
	int getValue(int gl,int gr){
		return getValueUtil(0, 0, n-1, gl, gr);
	}
	int getValueUtil(int root,int l,int r,int gl,int gr){
		if(l>=gl&&r<=gr){
			return s[root];
		}
		if(l>gr||r<gl){
			return n;
		}
		return Compare(getValueUtil(2*root+1, l, (l+r)/2, gl, gr), getValueUtil(2*root+2, (l+r)/2+1, r, gl, gr));
	}
	void update(int p,int k){
		updateUtil(p, k,0,0,n-1);
	}
	int updateUtil(int p,int k,int root,int l,int r){
		if(l==r&&l==k){
			return s[root]=p;
		}
		else if(l>k||r<k)
		return s[root];
		else{
			return s[root]=Compare(updateUtil(p, k, 2*root+1, l, (l+r)/2), updateUtil(p, k, 2*root+2,(l+r)/2+1,r ));
		}
	}
	int Compare(int a,int b){
        if(a>=n&&b>=n){
            System.out.println("adfna");
        }
        
		if(a>=n){
            return b;
        }
        if(b>=n){
            return a;
        }
        if(li[a]==li[b]){
            if(qn[a]>qn[b]){
                return a;
            }
            else return b;
        }
        else if(li[a]<li[b])
        return b;
        else return a;


	}
}

    
    
        
    