import java.util.*;
import java.io.*;
import java.lang.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
 public class Main {
    static ArrayList<String> s1;
    static boolean[] prime;
    static int n = (int)1e7;
     static void sieve() {
Arrays.fill(prime	, true);
prime[0] = prime[1] = false;
for(int i = 2 ; i * i <= n ; ++i) {
if(prime[i]) {
for(int k = i * i; k< n ; k+=i) {
prime[k] = false;
}
}
}
 
}
    public static void main(String[] args) {
        InputReader sc = new InputReader(System.in);
        
           prime  = new boolean[n + 1];
sieve();
                prime[1] = false;
                
             
           
            int x = sc.ni();
            int []a = sc.nia(x);
            int c = 0;
            for(int i=2;i<x;i++)
            {
                if((a[i-1] <= a[i-2] && a[i-1] > a[i]) || (a[i-1]<=a[i] && a[i-1]>a[i-2]))
                {
                    c++;
                }
            }
            
          w.println(c);
             
             
          
                  
              
              
 
       w.close();
        
    }
    static void bfs(int s)
    {
        vis[s] = true;
        Queue<Integer> q = new LinkedList<>();
        q.add(s);
        color[s] = 1;
        level[s] = 0;
        p[s] = s;
        while(q.size()>0)
        {
            int cc = q.poll();
          
            //ArrayList<Integer> te= new ArrayList<>();
            Iterator itr = hs[cc].iterator();
            while(itr.hasNext())
            {
                Integer e = (Integer) itr.next();
                //w.print(e + " ");
                 
                if(!vis[e])
                {
                   
                    q.add(e);
                   // te.add(e);
                    p[e] = cc;
                    if(color[cc]==1)
                        color[e] = 2;
                    else
                        color[e] = 1;
                    level[e] = level[cc]+1;
                    vis[e] = true;
                }
            }
           // w.println();
           
        }
        
    }
    static int []level;
     static int []color;
    static ArrayList<Integer> []hs;
    static boolean []vis;
    static int count = 0;
    static int []p;
  
    //static int [][]arr;
    static boolean [][]v;
    //static int [][]l;
  static boolean con(int []p,int q)
  {
    boolean res = false;
    for(int i=0;i<6;i++)
    {
      if(p[i]==q)
      {
        res = true;
        break;
      }
    }
    return res;
  }
    static String replace(String s,int a,int n)
    {
        char []c = s.toCharArray();
        for(int i=1;i<n;i+=2)
        {
            int num = (int) (c[i] - 48);
            num += a;
            num%=10;
            c[i] = (char) (num+48);
        }
        return new String(c);
    }
    static String move(String s,int h,int n)
    {
        h%=n;
        char []c = s.toCharArray();
        char []temp = new char[n];
        for(int i=0;i<n;i++)
        {
            temp[(i+h)%n] = c[i];
        }
        return new String(temp);
    }
    
     public static int ip(String s){
return Integer.parseInt(s);
}
     static class multipliers implements Comparator<Long>{
  
  public int compare(Long a,Long b) {
   if(a<b)
    return 1;
   else if(b<a)
    return -1;
   else
    return 0;
  }
 }
     static class multipliers1 implements Comparator<Student>{
  
  public int compare(Student a,Student b) {
   if(a.y<b.y)
    return 1;
   else if(b.y<a.y)
    return -1;
   else
   {
       if(a.id < b.id)
           return 1;
       else if(b.id<a.id)
           return -1;
       else
           return 0;
           
    //return 0;
   }
  }
 }
    // Java program to generate power set in 
// lexicographic order. 
 
    
    
    
      static class InputReader {
 
private final InputStream stream;
private final byte[] buf = new byte[8192];
private int curChar, snumChars;
 
public InputReader(InputStream st) {
this.stream = st;
}
 
public int read() {
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 ni() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
 
public long nl() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
 
public int[] nia(int n) {
int a[] = new int[n];
for (int i = 0; i < n; i++) {
a[i] = ni();
}
return a;
}
 
public String rs() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
 
public String nextLine() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isEndOfLine(c));
return res.toString();
}
 
public boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
 
private boolean isEndOfLine(int c) {
return c == '\n' || c == '\r' || c == -1;
}
 
}
 
 
 
 
 
   
static PrintWriter w = new PrintWriter(System.out);
                  static class Student
    {
        int id;
        //int x;
       
        int y;
        //long z;
        
        Student(int id,int y)
        {
            this.id = id;
            //this.x = x;
            //this.s = s;
            this.y = y;
           // this.z = z;
            
            
            
        }
        
    }
} import java.util.*; util.* java import java.io.*; io.* java import java.lang.*; lang.* java import java.text.*; text.* java import java.math.*; math.* java import java.util.regex.*; regex.* java.util public class Main {
    static ArrayList<String> s1;
    static boolean[] prime;
    static int n = (int)1e7;
     static void sieve() {
Arrays.fill(prime	, true);
prime[0] = prime[1] = false;
for(int i = 2 ; i * i <= n ; ++i) {
if(prime[i]) {
for(int k = i * i; k< n ; k+=i) {
prime[k] = false;
}
}
}
 
}
    public static void main(String[] args) {
        InputReader sc = new InputReader(System.in);
        
           prime  = new boolean[n + 1];
sieve();
                prime[1] = false;
                
             
           
            int x = sc.ni();
            int []a = sc.nia(x);
            int c = 0;
            for(int i=2;i<x;i++)
            {
                if((a[i-1] <= a[i-2] && a[i-1] > a[i]) || (a[i-1]<=a[i] && a[i-1]>a[i-2]))
                {
                    c++;
                }
            }
            
          w.println(c);
             
             
          
                  
              
              
 
       w.close();
        
    }
    static void bfs(int s)
    {
        vis[s] = true;
        Queue<Integer> q = new LinkedList<>();
        q.add(s);
        color[s] = 1;
        level[s] = 0;
        p[s] = s;
        while(q.size()>0)
        {
            int cc = q.poll();
          
            //ArrayList<Integer> te= new ArrayList<>();
            Iterator itr = hs[cc].iterator();
            while(itr.hasNext())
            {
                Integer e = (Integer) itr.next();
                //w.print(e + " ");
                 
                if(!vis[e])
                {
                   
                    q.add(e);
                   // te.add(e);
                    p[e] = cc;
                    if(color[cc]==1)
                        color[e] = 2;
                    else
                        color[e] = 1;
                    level[e] = level[cc]+1;
                    vis[e] = true;
                }
            }
           // w.println();
           
        }
        
    }
    static int []level;
     static int []color;
    static ArrayList<Integer> []hs;
    static boolean []vis;
    static int count = 0;
    static int []p;
  
    //static int [][]arr;
    static boolean [][]v;
    //static int [][]l;
  static boolean con(int []p,int q)
  {
    boolean res = false;
    for(int i=0;i<6;i++)
    {
      if(p[i]==q)
      {
        res = true;
        break;
      }
    }
    return res;
  }
    static String replace(String s,int a,int n)
    {
        char []c = s.toCharArray();
        for(int i=1;i<n;i+=2)
        {
            int num = (int) (c[i] - 48);
            num += a;
            num%=10;
            c[i] = (char) (num+48);
        }
        return new String(c);
    }
    static String move(String s,int h,int n)
    {
        h%=n;
        char []c = s.toCharArray();
        char []temp = new char[n];
        for(int i=0;i<n;i++)
        {
            temp[(i+h)%n] = c[i];
        }
        return new String(temp);
    }
    
     public static int ip(String s){
return Integer.parseInt(s);
}
     static class multipliers implements Comparator<Long>{
  
  public int compare(Long a,Long b) {
   if(a<b)
    return 1;
   else if(b<a)
    return -1;
   else
    return 0;
  }
 }
     static class multipliers1 implements Comparator<Student>{
  
  public int compare(Student a,Student b) {
   if(a.y<b.y)
    return 1;
   else if(b.y<a.y)
    return -1;
   else
   {
       if(a.id < b.id)
           return 1;
       else if(b.id<a.id)
           return -1;
       else
           return 0;
           
    //return 0;
   }
  }
 }
    // Java program to generate power set in 
// lexicographic order. 
 
    
    
    
      static class InputReader {
 
private final InputStream stream;
private final byte[] buf = new byte[8192];
private int curChar, snumChars;
 
public InputReader(InputStream st) {
this.stream = st;
}
 
public int read() {
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 ni() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
 
public long nl() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
 
public int[] nia(int n) {
int a[] = new int[n];
for (int i = 0; i < n; i++) {
a[i] = ni();
}
return a;
}
 
public String rs() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
 
public String nextLine() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isEndOfLine(c));
return res.toString();
}
 
public boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
 
private boolean isEndOfLine(int c) {
return c == '\n' || c == '\r' || c == -1;
}
 
}
 
 
 
 
 
   
static PrintWriter w = new PrintWriter(System.out);
                  static class Student
    {
        int id;
        //int x;
       
        int y;
        //long z;
        
        Student(int id,int y)
        {
            this.id = id;
            //this.x = x;
            //this.s = s;
            this.y = y;
           // this.z = z;
            
            
            
        }
        
    }
} Main static ArrayList<String> s1; s1 static boolean[] prime; prime static int n = (int)1e7; n (int)1e7 static int []level; level static int []color; color static ArrayList<Integer> []hs; hs static boolean []vis; vis static int count = 0; count 0 static int []p; p //static int [][]arr;
    static boolean [][]v; v static PrintWriter w = new PrintWriter(System.out); w new PrintWriter(System.out) static void sieve() {
Arrays.fill(prime	, true);
prime[0] = prime[1] = false;
for(int i = 2 ; i * i <= n ; ++i) {
if(prime[i]) {
for(int k = i * i; k< n ; k+=i) {
prime[k] = false;
}
}
}
 
} sieve {
Arrays.fill(prime	, true);
prime[0] = prime[1] = false;
for(int i = 2 ; i * i <= n ; ++i) {
if(prime[i]) {
for(int k = i * i; k< n ; k+=i) {
prime[k] = false;
}
}
}
 
} Arrays.fill(prime	, true) Arrays.fill Arrays prime true prime[0] = prime[1] = false prime[0] prime 0 prime[1] = false prime[1] prime 1 false for(int i = 2 ; i * i <= n ; ++i) {
if(prime[i]) {
for(int k = i * i; k< n ; k+=i) {
prime[k] = false;
}
}
} int i = 2 ; int i = 2 ; i 2 i * i <= n i * i i i n ++i ++i i {
if(prime[i]) {
for(int k = i * i; k< n ; k+=i) {
prime[k] = false;
}
}
} {
if(prime[i]) {
for(int k = i * i; k< n ; k+=i) {
prime[k] = false;
}
}
} if(prime[i]) {
for(int k = i * i; k< n ; k+=i) {
prime[k] = false;
}
} prime[i] prime i {
for(int k = i * i; k< n ; k+=i) {
prime[k] = false;
}
} for(int k = i * i; k< n ; k+=i) {
prime[k] = false;
} int k = i * i; int k = i * i; k i * i i i k< n k n k+=i k+=i k i {
prime[k] = false;
} {
prime[k] = false;
} prime[k] = false prime[k] prime k false public static void main(String[] args) {
        InputReader sc = new InputReader(System.in);
        
           prime  = new boolean[n + 1];
sieve();
                prime[1] = false;
                
             
           
            int x = sc.ni();
            int []a = sc.nia(x);
            int c = 0;
            for(int i=2;i<x;i++)
            {
                if((a[i-1] <= a[i-2] && a[i-1] > a[i]) || (a[i-1]<=a[i] && a[i-1]>a[i-2]))
                {
                    c++;
                }
            }
            
          w.println(c);
             
             
          
                  
              
              
 
       w.close();
        
    } main {
        InputReader sc = new InputReader(System.in);
        
           prime  = new boolean[n + 1];
sieve();
                prime[1] = false;
                
             
           
            int x = sc.ni();
            int []a = sc.nia(x);
            int c = 0;
            for(int i=2;i<x;i++)
            {
                if((a[i-1] <= a[i-2] && a[i-1] > a[i]) || (a[i-1]<=a[i] && a[i-1]>a[i-2]))
                {
                    c++;
                }
            }
            
          w.println(c);
             
             
          
                  
              
              
 
       w.close();
        
    } InputReader sc = new InputReader(System.in); sc new InputReader(System.in) prime  = new boolean[n + 1] prime new boolean[n + 1] n + 1 n 1 sieve() sieve prime[1] = false prime[1] prime 1 false int x = sc.ni(); x sc.ni() sc.ni sc int []a = sc.nia(x); a sc.nia(x) sc.nia sc x int c = 0; c 0 for(int i=2;i<x;i++)
            {
                if((a[i-1] <= a[i-2] && a[i-1] > a[i]) || (a[i-1]<=a[i] && a[i-1]>a[i-2]))
                {
                    c++;
                }
            } int i=2; int i=2; i 2 i<x i x i++ i++ i {
                if((a[i-1] <= a[i-2] && a[i-1] > a[i]) || (a[i-1]<=a[i] && a[i-1]>a[i-2]))
                {
                    c++;
                }
            } {
                if((a[i-1] <= a[i-2] && a[i-1] > a[i]) || (a[i-1]<=a[i] && a[i-1]>a[i-2]))
                {
                    c++;
                }
            } if((a[i-1] <= a[i-2] && a[i-1] > a[i]) || (a[i-1]<=a[i] && a[i-1]>a[i-2]))
                {
                    c++;
                } (a[i-1] <= a[i-2] && a[i-1] > a[i]) || (a[i-1]<=a[i] && a[i-1]>a[i-2]) (a[i-1] <= a[i-2] && a[i-1] > a[i]) a[i-1] <= a[i-2] a[i-1] a i-1 i 1 a[i-2] a i-2 i 2 a[i-1] > a[i] a[i-1] a i-1 i 1 a[i] a i (a[i-1]<=a[i] && a[i-1]>a[i-2]) a[i-1]<=a[i] a[i-1] a i-1 i 1 a[i] a i a[i-1]>a[i-2] a[i-1] a i-1 i 1 a[i-2] a i-2 i 2 {
                    c++;
                } c++ c w.println(c) w.println w c w.close() w.close w String[] args args static void bfs(int s)
    {
        vis[s] = true;
        Queue<Integer> q = new LinkedList<>();
        q.add(s);
        color[s] = 1;
        level[s] = 0;
        p[s] = s;
        while(q.size()>0)
        {
            int cc = q.poll();
          
            //ArrayList<Integer> te= new ArrayList<>();
            Iterator itr = hs[cc].iterator();
            while(itr.hasNext())
            {
                Integer e = (Integer) itr.next();
                //w.print(e + " ");
                 
                if(!vis[e])
                {
                   
                    q.add(e);
                   // te.add(e);
                    p[e] = cc;
                    if(color[cc]==1)
                        color[e] = 2;
                    else
                        color[e] = 1;
                    level[e] = level[cc]+1;
                    vis[e] = true;
                }
            }
           // w.println();
           
        }
        
    } bfs {
        vis[s] = true;
        Queue<Integer> q = new LinkedList<>();
        q.add(s);
        color[s] = 1;
        level[s] = 0;
        p[s] = s;
        while(q.size()>0)
        {
            int cc = q.poll();
          
            //ArrayList<Integer> te= new ArrayList<>();
            Iterator itr = hs[cc].iterator();
            while(itr.hasNext())
            {
                Integer e = (Integer) itr.next();
                //w.print(e + " ");
                 
                if(!vis[e])
                {
                   
                    q.add(e);
                   // te.add(e);
                    p[e] = cc;
                    if(color[cc]==1)
                        color[e] = 2;
                    else
                        color[e] = 1;
                    level[e] = level[cc]+1;
                    vis[e] = true;
                }
            }
           // w.println();
           
        }
        
    } vis[s] = true vis[s] vis s true Queue<Integer> q = new LinkedList<>(); q new LinkedList<>() q.add(s) q.add q s color[s] = 1 color[s] color s 1 level[s] = 0 level[s] level s 0 p[s] = s p[s] p s s while(q.size()>0)
        {
            int cc = q.poll();
          
            //ArrayList<Integer> te= new ArrayList<>();
            Iterator itr = hs[cc].iterator();
            while(itr.hasNext())
            {
                Integer e = (Integer) itr.next();
                //w.print(e + " ");
                 
                if(!vis[e])
                {
                   
                    q.add(e);
                   // te.add(e);
                    p[e] = cc;
                    if(color[cc]==1)
                        color[e] = 2;
                    else
                        color[e] = 1;
                    level[e] = level[cc]+1;
                    vis[e] = true;
                }
            }
           // w.println();
           
        } q.size()>0 q.size() q.size q 0 {
            int cc = q.poll();
          
            //ArrayList<Integer> te= new ArrayList<>();
            Iterator itr = hs[cc].iterator();
            while(itr.hasNext())
            {
                Integer e = (Integer) itr.next();
                //w.print(e + " ");
                 
                if(!vis[e])
                {
                   
                    q.add(e);
                   // te.add(e);
                    p[e] = cc;
                    if(color[cc]==1)
                        color[e] = 2;
                    else
                        color[e] = 1;
                    level[e] = level[cc]+1;
                    vis[e] = true;
                }
            }
           // w.println();
           
        } int cc = q.poll(); cc q.poll() q.poll q Iterator itr = hs[cc].iterator(); itr hs[cc].iterator() hs[cc].iterator hs[cc] hs cc while(itr.hasNext())
            {
                Integer e = (Integer) itr.next();
                //w.print(e + " ");
                 
                if(!vis[e])
                {
                   
                    q.add(e);
                   // te.add(e);
                    p[e] = cc;
                    if(color[cc]==1)
                        color[e] = 2;
                    else
                        color[e] = 1;
                    level[e] = level[cc]+1;
                    vis[e] = true;
                }
            } itr.hasNext() itr.hasNext itr {
                Integer e = (Integer) itr.next();
                //w.print(e + " ");
                 
                if(!vis[e])
                {
                   
                    q.add(e);
                   // te.add(e);
                    p[e] = cc;
                    if(color[cc]==1)
                        color[e] = 2;
                    else
                        color[e] = 1;
                    level[e] = level[cc]+1;
                    vis[e] = true;
                }
            } Integer e = (Integer) itr.next(); e (Integer) itr.next() itr.next itr if(!vis[e])
                {
                   
                    q.add(e);
                   // te.add(e);
                    p[e] = cc;
                    if(color[cc]==1)
                        color[e] = 2;
                    else
                        color[e] = 1;
                    level[e] = level[cc]+1;
                    vis[e] = true;
                } !vis[e] vis[e] vis e {
                   
                    q.add(e);
                   // te.add(e);
                    p[e] = cc;
                    if(color[cc]==1)
                        color[e] = 2;
                    else
                        color[e] = 1;
                    level[e] = level[cc]+1;
                    vis[e] = true;
                } q.add(e) q.add q e p[e] = cc p[e] p e cc if(color[cc]==1)
                        color[e] = 2;
                    else
                        color[e] = 1; color[cc]==1 color[cc] color cc 1 color[e] = 2 color[e] color e 2 color[e] = 1 color[e] color e 1 level[e] = level[cc]+1 level[e] level e level[cc]+1 level[cc] level cc 1 vis[e] = true vis[e] vis e true int s s //static int [][]l;
  static boolean con(int []p,int q)
  {
    boolean res = false;
    for(int i=0;i<6;i++)
    {
      if(p[i]==q)
      {
        res = true;
        break;
      }
    }
    return res;
  } con {
    boolean res = false;
    for(int i=0;i<6;i++)
    {
      if(p[i]==q)
      {
        res = true;
        break;
      }
    }
    return res;
  } boolean res = false; res false for(int i=0;i<6;i++)
    {
      if(p[i]==q)
      {
        res = true;
        break;
      }
    } int i=0; int i=0; i 0 i<6 i 6 i++ i++ i {
      if(p[i]==q)
      {
        res = true;
        break;
      }
    } {
      if(p[i]==q)
      {
        res = true;
        break;
      }
    } if(p[i]==q)
      {
        res = true;
        break;
      } p[i]==q p[i] p i q {
        res = true;
        break;
      } res = true res true break; return res; res int []p p int q q static String replace(String s,int a,int n)
    {
        char []c = s.toCharArray();
        for(int i=1;i<n;i+=2)
        {
            int num = (int) (c[i] - 48);
            num += a;
            num%=10;
            c[i] = (char) (num+48);
        }
        return new String(c);
    } replace {
        char []c = s.toCharArray();
        for(int i=1;i<n;i+=2)
        {
            int num = (int) (c[i] - 48);
            num += a;
            num%=10;
            c[i] = (char) (num+48);
        }
        return new String(c);
    } char []c = s.toCharArray(); c s.toCharArray() s.toCharArray s for(int i=1;i<n;i+=2)
        {
            int num = (int) (c[i] - 48);
            num += a;
            num%=10;
            c[i] = (char) (num+48);
        } int i=1; int i=1; i 1 i<n i n i+=2 i+=2 i 2 {
            int num = (int) (c[i] - 48);
            num += a;
            num%=10;
            c[i] = (char) (num+48);
        } {
            int num = (int) (c[i] - 48);
            num += a;
            num%=10;
            c[i] = (char) (num+48);
        } int num = (int) (c[i] - 48); num (int) (c[i] - 48) c[i] c i 48 num += a num a num%=10 num 10 c[i] = (char) (num+48) c[i] c i (char) (num+48) num 48 return new String(c); new String(c) String s s int a a int n n static String move(String s,int h,int n)
    {
        h%=n;
        char []c = s.toCharArray();
        char []temp = new char[n];
        for(int i=0;i<n;i++)
        {
            temp[(i+h)%n] = c[i];
        }
        return new String(temp);
    } move {
        h%=n;
        char []c = s.toCharArray();
        char []temp = new char[n];
        for(int i=0;i<n;i++)
        {
            temp[(i+h)%n] = c[i];
        }
        return new String(temp);
    } h%=n h n char []c = s.toCharArray(); c s.toCharArray() s.toCharArray s char []temp = new char[n]; temp new char[n] n for(int i=0;i<n;i++)
        {
            temp[(i+h)%n] = c[i];
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            temp[(i+h)%n] = c[i];
        } {
            temp[(i+h)%n] = c[i];
        } temp[(i+h)%n] = c[i] temp[(i+h)%n] temp (i+h)%n (i+h) i h n c[i] c i return new String(temp); new String(temp) String s s int h h int n n public static int ip(String s){
return Integer.parseInt(s);
} ip {
return Integer.parseInt(s);
} return Integer.parseInt(s); Integer.parseInt(s) Integer.parseInt Integer s String s s static class multipliers implements Comparator<Long>{
  
  public int compare(Long a,Long b) {
   if(a<b)
    return 1;
   else if(b<a)
    return -1;
   else
    return 0;
  }
 } multipliers public int compare(Long a,Long b) {
   if(a<b)
    return 1;
   else if(b<a)
    return -1;
   else
    return 0;
  } compare {
   if(a<b)
    return 1;
   else if(b<a)
    return -1;
   else
    return 0;
  } if(a<b)
    return 1;
   else if(b<a)
    return -1;
   else
    return 0; a<b a b return 1; 1 if(b<a)
    return -1;
   else
    return 0; b<a b a return -1; -1 1 return 0; 0 Long a a Long b b Comparator static class multipliers1 implements Comparator<Student>{
  
  public int compare(Student a,Student b) {
   if(a.y<b.y)
    return 1;
   else if(b.y<a.y)
    return -1;
   else
   {
       if(a.id < b.id)
           return 1;
       else if(b.id<a.id)
           return -1;
       else
           return 0;
           
    //return 0;
   }
  }
 } multipliers1 public int compare(Student a,Student b) {
   if(a.y<b.y)
    return 1;
   else if(b.y<a.y)
    return -1;
   else
   {
       if(a.id < b.id)
           return 1;
       else if(b.id<a.id)
           return -1;
       else
           return 0;
           
    //return 0;
   }
  } compare {
   if(a.y<b.y)
    return 1;
   else if(b.y<a.y)
    return -1;
   else
   {
       if(a.id < b.id)
           return 1;
       else if(b.id<a.id)
           return -1;
       else
           return 0;
           
    //return 0;
   }
  } if(a.y<b.y)
    return 1;
   else if(b.y<a.y)
    return -1;
   else
   {
       if(a.id < b.id)
           return 1;
       else if(b.id<a.id)
           return -1;
       else
           return 0;
           
    //return 0;
   } a.y<b.y a.y a a.y b.y b b.y return 1; 1 if(b.y<a.y)
    return -1;
   else
   {
       if(a.id < b.id)
           return 1;
       else if(b.id<a.id)
           return -1;
       else
           return 0;
           
    //return 0;
   } b.y<a.y b.y b b.y a.y a a.y return -1; -1 1 {
       if(a.id < b.id)
           return 1;
       else if(b.id<a.id)
           return -1;
       else
           return 0;
           
    //return 0;
   } if(a.id < b.id)
           return 1;
       else if(b.id<a.id)
           return -1;
       else
           return 0; a.id < b.id a.id a a.id b.id b b.id return 1; 1 if(b.id<a.id)
           return -1;
       else
           return 0; b.id<a.id b.id b b.id a.id a a.id return -1; -1 1 return 0; 0 Student a a Student b b Comparator static class InputReader {
 
private final InputStream stream;
private final byte[] buf = new byte[8192];
private int curChar, snumChars;
 
public InputReader(InputStream st) {
this.stream = st;
}
 
public int read() {
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 ni() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
 
public long nl() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
 
public int[] nia(int n) {
int a[] = new int[n];
for (int i = 0; i < n; i++) {
a[i] = ni();
}
return a;
}
 
public String rs() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
 
public String nextLine() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isEndOfLine(c));
return res.toString();
}
 
public boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
 
private boolean isEndOfLine(int c) {
return c == '\n' || c == '\r' || c == -1;
}
 
} InputReader private final InputStream stream; stream private final byte[] buf = new byte[8192]; buf new byte[8192] 8192 private int curChar curChar snumChars; snumChars public InputReader(InputStream st) {
this.stream = st;
} InputReader {
this.stream = st;
} this.stream = st this.stream this this.stream st InputStream st st public int read() {
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++];
} read {
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++];
} if (snumChars == -1)
throw new InputMismatchException(); snumChars == -1 snumChars -1 1 throw new InputMismatchException(); new InputMismatchException() if (curChar >= snumChars) {
curChar = 0;
try {
snumChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (snumChars <= 0)
return -1;
} curChar >= snumChars curChar snumChars {
curChar = 0;
try {
snumChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (snumChars <= 0)
return -1;
} curChar = 0 curChar 0 try {
snumChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
} catch (IOException e) {
throw new InputMismatchException();
} IOException e {
throw new InputMismatchException();
} throw new InputMismatchException(); new InputMismatchException() {
snumChars = stream.read(buf);
} snumChars = stream.read(buf) snumChars stream.read(buf) stream.read stream buf if (snumChars <= 0)
return -1; snumChars <= 0 snumChars 0 return -1; -1 1 return buf[curChar++]; buf[curChar++] buf curChar++ curChar public int ni() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
} ni {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
} int c = read(); c read() read while (isSpaceChar(c)) {
c = read();
} isSpaceChar(c) isSpaceChar c {
c = read();
} c = read() c read() read int sgn = 1; sgn 1 if (c == '-') {
sgn = -1;
c = read();
} c == '-' c '-' {
sgn = -1;
c = read();
} sgn = -1 sgn -1 1 c = read() c read() read int res = 0; res 0 do {
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c)); !isSpaceChar(c) isSpaceChar(c) isSpaceChar c {
res *= 10;
res += c - '0';
c = read();
} res *= 10 res 10 res += c - '0' res c - '0' c '0' c = read() c read() read return res * sgn; res * sgn res sgn public long nl() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
} nl {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
} int c = read(); c read() read while (isSpaceChar(c)) {
c = read();
} isSpaceChar(c) isSpaceChar c {
c = read();
} c = read() c read() read int sgn = 1; sgn 1 if (c == '-') {
sgn = -1;
c = read();
} c == '-' c '-' {
sgn = -1;
c = read();
} sgn = -1 sgn -1 1 c = read() c read() read long res = 0; res 0 do {
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c)); !isSpaceChar(c) isSpaceChar(c) isSpaceChar c {
res *= 10;
res += c - '0';
c = read();
} res *= 10 res 10 res += c - '0' res c - '0' c '0' c = read() c read() read return res * sgn; res * sgn res sgn public int[] nia(int n) {
int a[] = new int[n];
for (int i = 0; i < n; i++) {
a[i] = ni();
}
return a;
} nia {
int a[] = new int[n];
for (int i = 0; i < n; i++) {
a[i] = ni();
}
return a;
} int a[] = new int[n]; a new int[n] n for (int i = 0; i < n; i++) {
a[i] = ni();
} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
a[i] = ni();
} {
a[i] = ni();
} a[i] = ni() a[i] a i ni() ni return a; a int n n public String rs() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
} rs {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
} int c = read(); c read() read while (isSpaceChar(c)) {
c = read();
} isSpaceChar(c) isSpaceChar c {
c = read();
} c = read() c read() read StringBuilder res = new StringBuilder(); res new StringBuilder() do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c)); !isSpaceChar(c) isSpaceChar(c) isSpaceChar c {
res.appendCodePoint(c);
c = read();
} res.appendCodePoint(c) res.appendCodePoint res c c = read() c read() read return res.toString(); res.toString() res.toString res public String nextLine() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isEndOfLine(c));
return res.toString();
} nextLine {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isEndOfLine(c));
return res.toString();
} int c = read(); c read() read while (isSpaceChar(c))
c = read(); isSpaceChar(c) isSpaceChar c c = read() c read() read StringBuilder res = new StringBuilder(); res new StringBuilder() do {
res.appendCodePoint(c);
c = read();
} while (!isEndOfLine(c)); !isEndOfLine(c) isEndOfLine(c) isEndOfLine c {
res.appendCodePoint(c);
c = read();
} res.appendCodePoint(c) res.appendCodePoint res c c = read() c read() read return res.toString(); res.toString() res.toString res public boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
} isSpaceChar {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
} return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1 c == '\t' c == '\r' c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1 c == ' ' c ' ' c == '\n' c '\n' c == '\r' c '\r' c == '\t' c '\t' c == -1 c -1 1 int c c private boolean isEndOfLine(int c) {
return c == '\n' || c == '\r' || c == -1;
} isEndOfLine {
return c == '\n' || c == '\r' || c == -1;
} return c == '\n' || c == '\r' || c == -1; c == '\n' || c == '\r' || c == -1 c == '\n' || c == '\r' || c == -1 c == '\n' c '\n' c == '\r' c '\r' c == -1 c -1 1 int c c static class Student
    {
        int id;
        //int x;
       
        int y;
        //long z;
        
        Student(int id,int y)
        {
            this.id = id;
            //this.x = x;
            //this.s = s;
            this.y = y;
           // this.z = z;
            
            
            
        }
        
    } Student int id; id int y; y Student(int id,int y)
        {
            this.id = id;
            //this.x = x;
            //this.s = s;
            this.y = y;
           // this.z = z;
            
            
            
        } Student {
            this.id = id;
            //this.x = x;
            //this.s = s;
            this.y = y;
           // this.z = z;
            
            
            
        } this.id = id this.id this this.id id this.y = y this.y this this.y y int id id int y y public class Main {
    static ArrayList<String> s1;
    static boolean[] prime;
    static int n = (int)1e7;
     static void sieve() {
Arrays.fill(prime	, true);
prime[0] = prime[1] = false;
for(int i = 2 ; i * i <= n ; ++i) {
if(prime[i]) {
for(int k = i * i; k< n ; k+=i) {
prime[k] = false;
}
}
}
 
}
    public static void main(String[] args) {
        InputReader sc = new InputReader(System.in);
        
           prime  = new boolean[n + 1];
sieve();
                prime[1] = false;
                
             
           
            int x = sc.ni();
            int []a = sc.nia(x);
            int c = 0;
            for(int i=2;i<x;i++)
            {
                if((a[i-1] <= a[i-2] && a[i-1] > a[i]) || (a[i-1]<=a[i] && a[i-1]>a[i-2]))
                {
                    c++;
                }
            }
            
          w.println(c);
             
             
          
                  
              
              
 
       w.close();
        
    }
    static void bfs(int s)
    {
        vis[s] = true;
        Queue<Integer> q = new LinkedList<>();
        q.add(s);
        color[s] = 1;
        level[s] = 0;
        p[s] = s;
        while(q.size()>0)
        {
            int cc = q.poll();
          
            //ArrayList<Integer> te= new ArrayList<>();
            Iterator itr = hs[cc].iterator();
            while(itr.hasNext())
            {
                Integer e = (Integer) itr.next();
                //w.print(e + " ");
                 
                if(!vis[e])
                {
                   
                    q.add(e);
                   // te.add(e);
                    p[e] = cc;
                    if(color[cc]==1)
                        color[e] = 2;
                    else
                        color[e] = 1;
                    level[e] = level[cc]+1;
                    vis[e] = true;
                }
            }
           // w.println();
           
        }
        
    }
    static int []level;
     static int []color;
    static ArrayList<Integer> []hs;
    static boolean []vis;
    static int count = 0;
    static int []p;
  
    //static int [][]arr;
    static boolean [][]v;
    //static int [][]l;
  static boolean con(int []p,int q)
  {
    boolean res = false;
    for(int i=0;i<6;i++)
    {
      if(p[i]==q)
      {
        res = true;
        break;
      }
    }
    return res;
  }
    static String replace(String s,int a,int n)
    {
        char []c = s.toCharArray();
        for(int i=1;i<n;i+=2)
        {
            int num = (int) (c[i] - 48);
            num += a;
            num%=10;
            c[i] = (char) (num+48);
        }
        return new String(c);
    }
    static String move(String s,int h,int n)
    {
        h%=n;
        char []c = s.toCharArray();
        char []temp = new char[n];
        for(int i=0;i<n;i++)
        {
            temp[(i+h)%n] = c[i];
        }
        return new String(temp);
    }
    
     public static int ip(String s){
return Integer.parseInt(s);
}
     static class multipliers implements Comparator<Long>{
  
  public int compare(Long a,Long b) {
   if(a<b)
    return 1;
   else if(b<a)
    return -1;
   else
    return 0;
  }
 }
     static class multipliers1 implements Comparator<Student>{
  
  public int compare(Student a,Student b) {
   if(a.y<b.y)
    return 1;
   else if(b.y<a.y)
    return -1;
   else
   {
       if(a.id < b.id)
           return 1;
       else if(b.id<a.id)
           return -1;
       else
           return 0;
           
    //return 0;
   }
  }
 }
    // Java program to generate power set in 
// lexicographic order. 
 
    
    
    
      static class InputReader {
 
private final InputStream stream;
private final byte[] buf = new byte[8192];
private int curChar, snumChars;
 
public InputReader(InputStream st) {
this.stream = st;
}
 
public int read() {
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 ni() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
 
public long nl() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
 
public int[] nia(int n) {
int a[] = new int[n];
for (int i = 0; i < n; i++) {
a[i] = ni();
}
return a;
}
 
public String rs() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
 
public String nextLine() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isEndOfLine(c));
return res.toString();
}
 
public boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
 
private boolean isEndOfLine(int c) {
return c == '\n' || c == '\r' || c == -1;
}
 
}
 
 
 
 
 
   
static PrintWriter w = new PrintWriter(System.out);
                  static class Student
    {
        int id;
        //int x;
       
        int y;
        //long z;
        
        Student(int id,int y)
        {
            this.id = id;
            //this.x = x;
            //this.s = s;
            this.y = y;
           // this.z = z;
            
            
            
        }
        
    }
} public class Main {
    static ArrayList<String> s1;
    static boolean[] prime;
    static int n = (int)1e7;
     static void sieve() {
Arrays.fill(prime	, true);
prime[0] = prime[1] = false;
for(int i = 2 ; i * i <= n ; ++i) {
if(prime[i]) {
for(int k = i * i; k< n ; k+=i) {
prime[k] = false;
}
}
}
 
}
    public static void main(String[] args) {
        InputReader sc = new InputReader(System.in);
        
           prime  = new boolean[n + 1];
sieve();
                prime[1] = false;
                
             
           
            int x = sc.ni();
            int []a = sc.nia(x);
            int c = 0;
            for(int i=2;i<x;i++)
            {
                if((a[i-1] <= a[i-2] && a[i-1] > a[i]) || (a[i-1]<=a[i] && a[i-1]>a[i-2]))
                {
                    c++;
                }
            }
            
          w.println(c);
             
             
          
                  
              
              
 
       w.close();
        
    }
    static void bfs(int s)
    {
        vis[s] = true;
        Queue<Integer> q = new LinkedList<>();
        q.add(s);
        color[s] = 1;
        level[s] = 0;
        p[s] = s;
        while(q.size()>0)
        {
            int cc = q.poll();
          
            //ArrayList<Integer> te= new ArrayList<>();
            Iterator itr = hs[cc].iterator();
            while(itr.hasNext())
            {
                Integer e = (Integer) itr.next();
                //w.print(e + " ");
                 
                if(!vis[e])
                {
                   
                    q.add(e);
                   // te.add(e);
                    p[e] = cc;
                    if(color[cc]==1)
                        color[e] = 2;
                    else
                        color[e] = 1;
                    level[e] = level[cc]+1;
                    vis[e] = true;
                }
            }
           // w.println();
           
        }
        
    }
    static int []level;
     static int []color;
    static ArrayList<Integer> []hs;
    static boolean []vis;
    static int count = 0;
    static int []p;
  
    //static int [][]arr;
    static boolean [][]v;
    //static int [][]l;
  static boolean con(int []p,int q)
  {
    boolean res = false;
    for(int i=0;i<6;i++)
    {
      if(p[i]==q)
      {
        res = true;
        break;
      }
    }
    return res;
  }
    static String replace(String s,int a,int n)
    {
        char []c = s.toCharArray();
        for(int i=1;i<n;i+=2)
        {
            int num = (int) (c[i] - 48);
            num += a;
            num%=10;
            c[i] = (char) (num+48);
        }
        return new String(c);
    }
    static String move(String s,int h,int n)
    {
        h%=n;
        char []c = s.toCharArray();
        char []temp = new char[n];
        for(int i=0;i<n;i++)
        {
            temp[(i+h)%n] = c[i];
        }
        return new String(temp);
    }
    
     public static int ip(String s){
return Integer.parseInt(s);
}
     static class multipliers implements Comparator<Long>{
  
  public int compare(Long a,Long b) {
   if(a<b)
    return 1;
   else if(b<a)
    return -1;
   else
    return 0;
  }
 }
     static class multipliers1 implements Comparator<Student>{
  
  public int compare(Student a,Student b) {
   if(a.y<b.y)
    return 1;
   else if(b.y<a.y)
    return -1;
   else
   {
       if(a.id < b.id)
           return 1;
       else if(b.id<a.id)
           return -1;
       else
           return 0;
           
    //return 0;
   }
  }
 }
    // Java program to generate power set in 
// lexicographic order. 
 
    
    
    
      static class InputReader {
 
private final InputStream stream;
private final byte[] buf = new byte[8192];
private int curChar, snumChars;
 
public InputReader(InputStream st) {
this.stream = st;
}
 
public int read() {
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 ni() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
 
public long nl() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
 
public int[] nia(int n) {
int a[] = new int[n];
for (int i = 0; i < n; i++) {
a[i] = ni();
}
return a;
}
 
public String rs() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
 
public String nextLine() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isEndOfLine(c));
return res.toString();
}
 
public boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
 
private boolean isEndOfLine(int c) {
return c == '\n' || c == '\r' || c == -1;
}
 
}
 
 
 
 
 
   
static PrintWriter w = new PrintWriter(System.out);
                  static class Student
    {
        int id;
        //int x;
       
        int y;
        //long z;
        
        Student(int id,int y)
        {
            this.id = id;
            //this.x = x;
            //this.s = s;
            this.y = y;
           // this.z = z;
            
            
            
        }
        
    }
} Main
import java.util.*;
import java.io.*;
import java.lang.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
 public class Main {
    static ArrayList<String> s1;
    static boolean[] prime;
    static int n = (int)1e7;
     static void sieve() {
Arrays.fill(prime	, true);
prime[0] = prime[1] = false;
for(int i = 2 ; i * i <= n ; ++i) {
if(prime[i]) {
for(int k = i * i; k< n ; k+=i) {
prime[k] = false;
}
}
}
 
}
    public static void main(String[] args) {
        InputReader sc = new InputReader(System.in);
        
           prime  = new boolean[n + 1];
sieve();
                prime[1] = false;
                
             
           
            int x = sc.ni();
            int []a = sc.nia(x);
            int c = 0;
            for(int i=2;i<x;i++)
            {
                if((a[i-1] <= a[i-2] && a[i-1] > a[i]) || (a[i-1]<=a[i] && a[i-1]>a[i-2]))
                {
                    c++;
                }
            }
            
          w.println(c);
             
             
          
                  
              
              
 
       w.close();
        
    }
    static void bfs(int s)
    {
        vis[s] = true;
        Queue<Integer> q = new LinkedList<>();
        q.add(s);
        color[s] = 1;
        level[s] = 0;
        p[s] = s;
        while(q.size()>0)
        {
            int cc = q.poll();
          
            //ArrayList<Integer> te= new ArrayList<>();
            Iterator itr = hs[cc].iterator();
            while(itr.hasNext())
            {
                Integer e = (Integer) itr.next();
                //w.print(e + " ");
                 
                if(!vis[e])
                {
                   
                    q.add(e);
                   // te.add(e);
                    p[e] = cc;
                    if(color[cc]==1)
                        color[e] = 2;
                    else
                        color[e] = 1;
                    level[e] = level[cc]+1;
                    vis[e] = true;
                }
            }
           // w.println();
           
        }
        
    }
    static int []level;
     static int []color;
    static ArrayList<Integer> []hs;
    static boolean []vis;
    static int count = 0;
    static int []p;
  
    //static int [][]arr;
    static boolean [][]v;
    //static int [][]l;
  static boolean con(int []p,int q)
  {
    boolean res = false;
    for(int i=0;i<6;i++)
    {
      if(p[i]==q)
      {
        res = true;
        break;
      }
    }
    return res;
  }
    static String replace(String s,int a,int n)
    {
        char []c = s.toCharArray();
        for(int i=1;i<n;i+=2)
        {
            int num = (int) (c[i] - 48);
            num += a;
            num%=10;
            c[i] = (char) (num+48);
        }
        return new String(c);
    }
    static String move(String s,int h,int n)
    {
        h%=n;
        char []c = s.toCharArray();
        char []temp = new char[n];
        for(int i=0;i<n;i++)
        {
            temp[(i+h)%n] = c[i];
        }
        return new String(temp);
    }
    
     public static int ip(String s){
return Integer.parseInt(s);
}
     static class multipliers implements Comparator<Long>{
  
  public int compare(Long a,Long b) {
   if(a<b)
    return 1;
   else if(b<a)
    return -1;
   else
    return 0;
  }
 }
     static class multipliers1 implements Comparator<Student>{
  
  public int compare(Student a,Student b) {
   if(a.y<b.y)
    return 1;
   else if(b.y<a.y)
    return -1;
   else
   {
       if(a.id < b.id)
           return 1;
       else if(b.id<a.id)
           return -1;
       else
           return 0;
           
    //return 0;
   }
  }
 }
    // Java program to generate power set in 
// lexicographic order. 
 
    
    
    
      static class InputReader {
 
private final InputStream stream;
private final byte[] buf = new byte[8192];
private int curChar, snumChars;
 
public InputReader(InputStream st) {
this.stream = st;
}
 
public int read() {
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 ni() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
 
public long nl() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
 
public int[] nia(int n) {
int a[] = new int[n];
for (int i = 0; i < n; i++) {
a[i] = ni();
}
return a;
}
 
public String rs() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
 
public String nextLine() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
} while (!isEndOfLine(c));
return res.toString();
}
 
public boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
 
private boolean isEndOfLine(int c) {
return c == '\n' || c == '\r' || c == -1;
}
 
}
 
 
 
 
 
   
static PrintWriter w = new PrintWriter(System.out);
                  static class Student
    {
        int id;
        //int x;
       
        int y;
        //long z;
        
        Student(int id,int y)
        {
            this.id = id;
            //this.x = x;
            //this.s = s;
            this.y = y;
           // this.z = z;
            
            
            
        }
        
    }
}