import java.io.*;
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.next());
    int[] h = new int[N];
    for (int i = 0; i < N; i++) {
      h[i] = Integer.parseInt(sc.next());
    }
    
    int count = 0;
    int sum = 0;
    boolean flag = false;
    while (true) {
      for (int i = 0; i < N; i++) {
        if (h[i] != 0) {
          if (i == 0) {
            count++;
            flag = false;
          } else if (h[i-1] == 0 && flag) {
            count++;
            flag = false;
          }
          h[i]--;
        } else {
          flag = true;
        }
      }
      if (count == 0) {
        System.out.println(sum);
        return;
      }
      sum += count;
      count = 0;
    }
  }
} import java.io.*; io.* java import java.util.*; util.* java class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.next());
    int[] h = new int[N];
    for (int i = 0; i < N; i++) {
      h[i] = Integer.parseInt(sc.next());
    }
    
    int count = 0;
    int sum = 0;
    boolean flag = false;
    while (true) {
      for (int i = 0; i < N; i++) {
        if (h[i] != 0) {
          if (i == 0) {
            count++;
            flag = false;
          } else if (h[i-1] == 0 && flag) {
            count++;
            flag = false;
          }
          h[i]--;
        } else {
          flag = true;
        }
      }
      if (count == 0) {
        System.out.println(sum);
        return;
      }
      sum += count;
      count = 0;
    }
  }
} Main public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.next());
    int[] h = new int[N];
    for (int i = 0; i < N; i++) {
      h[i] = Integer.parseInt(sc.next());
    }
    
    int count = 0;
    int sum = 0;
    boolean flag = false;
    while (true) {
      for (int i = 0; i < N; i++) {
        if (h[i] != 0) {
          if (i == 0) {
            count++;
            flag = false;
          } else if (h[i-1] == 0 && flag) {
            count++;
            flag = false;
          }
          h[i]--;
        } else {
          flag = true;
        }
      }
      if (count == 0) {
        System.out.println(sum);
        return;
      }
      sum += count;
      count = 0;
    }
  } main {
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.next());
    int[] h = new int[N];
    for (int i = 0; i < N; i++) {
      h[i] = Integer.parseInt(sc.next());
    }
    
    int count = 0;
    int sum = 0;
    boolean flag = false;
    while (true) {
      for (int i = 0; i < N; i++) {
        if (h[i] != 0) {
          if (i == 0) {
            count++;
            flag = false;
          } else if (h[i-1] == 0 && flag) {
            count++;
            flag = false;
          }
          h[i]--;
        } else {
          flag = true;
        }
      }
      if (count == 0) {
        System.out.println(sum);
        return;
      }
      sum += count;
      count = 0;
    }
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = Integer.parseInt(sc.next()); N Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int[] h = new int[N]; h new int[N] N for (int i = 0; i < N; i++) {
      h[i] = Integer.parseInt(sc.next());
    } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
      h[i] = Integer.parseInt(sc.next());
    } {
      h[i] = Integer.parseInt(sc.next());
    } h[i] = Integer.parseInt(sc.next()) h[i] h i Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int count = 0; count 0 int sum = 0; sum 0 boolean flag = false; flag false while (true) {
      for (int i = 0; i < N; i++) {
        if (h[i] != 0) {
          if (i == 0) {
            count++;
            flag = false;
          } else if (h[i-1] == 0 && flag) {
            count++;
            flag = false;
          }
          h[i]--;
        } else {
          flag = true;
        }
      }
      if (count == 0) {
        System.out.println(sum);
        return;
      }
      sum += count;
      count = 0;
    } true {
      for (int i = 0; i < N; i++) {
        if (h[i] != 0) {
          if (i == 0) {
            count++;
            flag = false;
          } else if (h[i-1] == 0 && flag) {
            count++;
            flag = false;
          }
          h[i]--;
        } else {
          flag = true;
        }
      }
      if (count == 0) {
        System.out.println(sum);
        return;
      }
      sum += count;
      count = 0;
    } for (int i = 0; i < N; i++) {
        if (h[i] != 0) {
          if (i == 0) {
            count++;
            flag = false;
          } else if (h[i-1] == 0 && flag) {
            count++;
            flag = false;
          }
          h[i]--;
        } else {
          flag = true;
        }
      } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
        if (h[i] != 0) {
          if (i == 0) {
            count++;
            flag = false;
          } else if (h[i-1] == 0 && flag) {
            count++;
            flag = false;
          }
          h[i]--;
        } else {
          flag = true;
        }
      } {
        if (h[i] != 0) {
          if (i == 0) {
            count++;
            flag = false;
          } else if (h[i-1] == 0 && flag) {
            count++;
            flag = false;
          }
          h[i]--;
        } else {
          flag = true;
        }
      } if (h[i] != 0) {
          if (i == 0) {
            count++;
            flag = false;
          } else if (h[i-1] == 0 && flag) {
            count++;
            flag = false;
          }
          h[i]--;
        } else {
          flag = true;
        } h[i] != 0 h[i] h i 0 {
          if (i == 0) {
            count++;
            flag = false;
          } else if (h[i-1] == 0 && flag) {
            count++;
            flag = false;
          }
          h[i]--;
        } if (i == 0) {
            count++;
            flag = false;
          } else if (h[i-1] == 0 && flag) {
            count++;
            flag = false;
          } i == 0 i 0 {
            count++;
            flag = false;
          } count++ count flag = false flag false if (h[i-1] == 0 && flag) {
            count++;
            flag = false;
          } h[i-1] == 0 && flag h[i-1] == 0 h[i-1] h i-1 i 1 0 flag {
            count++;
            flag = false;
          } count++ count flag = false flag false h[i]-- h[i] h i {
          flag = true;
        } flag = true flag true if (count == 0) {
        System.out.println(sum);
        return;
      } count == 0 count 0 {
        System.out.println(sum);
        return;
      } System.out.println(sum) System.out.println System.out System System.out sum return; sum += count sum count count = 0 count 0 String[] args args
import java.io.*;
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.next());
    int[] h = new int[N];
    for (int i = 0; i < N; i++) {
      h[i] = Integer.parseInt(sc.next());
    }
    
    int count = 0;
    int sum = 0;
    boolean flag = false;
    while (true) {
      for (int i = 0; i < N; i++) {
        if (h[i] != 0) {
          if (i == 0) {
            count++;
            flag = false;
          } else if (h[i-1] == 0 && flag) {
            count++;
            flag = false;
          }
          h[i]--;
        } else {
          flag = true;
        }
      }
      if (count == 0) {
        System.out.println(sum);
        return;
      }
      sum += count;
      count = 0;
    }
  }
}