import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] h = new int[n];
    for(int i = 0; i < n; i++) {
      h[i] = sc.nextInt();
    }
    System.out.println(dfs(h));
  }

  public static int dfs(int[] hana) {
    int m = 100;
    for(int i = 0; i < hana.length; i++) {
      m = Math.min(m, hana[i]);
    }
    int ans = m;
    for(int i = 0; i < hana.length; i++) {
      hana[i] -= m;
    }
    int p = -1;
    int q = -1;
    int t = 0;
    for(int i = 0; i < hana.length; i++) {
      if(hana[i] > 0) {
        if(t == 0) {
          p = i;
          t = 1;
        } else {

        }
      } else {
        if(t == 1) {
          q = i - 1;
          t = 0;
          int[] hana2 = new int[q - p + 1];
          for(int j = 0; j < q - p + 1; j++) { 
            hana2[j] = hana[j + p];
          }
          ans += dfs(hana2);
          p = -1;
        }
      }
      if((i == hana.length - 1) && (p != -1)) {
        q = hana.length - 1;
        int[] hana2 = new int[q - p + 1];
        for(int j = 0; j < q - p + 1; j++) { 
          hana2[j] = hana[j + p];
        }
        ans += dfs(hana2);
      }
    }
    return ans;
  }
} import java.util.*; util.* java public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] h = new int[n];
    for(int i = 0; i < n; i++) {
      h[i] = sc.nextInt();
    }
    System.out.println(dfs(h));
  }

  public static int dfs(int[] hana) {
    int m = 100;
    for(int i = 0; i < hana.length; i++) {
      m = Math.min(m, hana[i]);
    }
    int ans = m;
    for(int i = 0; i < hana.length; i++) {
      hana[i] -= m;
    }
    int p = -1;
    int q = -1;
    int t = 0;
    for(int i = 0; i < hana.length; i++) {
      if(hana[i] > 0) {
        if(t == 0) {
          p = i;
          t = 1;
        } else {

        }
      } else {
        if(t == 1) {
          q = i - 1;
          t = 0;
          int[] hana2 = new int[q - p + 1];
          for(int j = 0; j < q - p + 1; j++) { 
            hana2[j] = hana[j + p];
          }
          ans += dfs(hana2);
          p = -1;
        }
      }
      if((i == hana.length - 1) && (p != -1)) {
        q = hana.length - 1;
        int[] hana2 = new int[q - p + 1];
        for(int j = 0; j < q - p + 1; j++) { 
          hana2[j] = hana[j + p];
        }
        ans += dfs(hana2);
      }
    }
    return ans;
  }
} Main public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] h = new int[n];
    for(int i = 0; i < n; i++) {
      h[i] = sc.nextInt();
    }
    System.out.println(dfs(h));
  } main {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] h = new int[n];
    for(int i = 0; i < n; i++) {
      h[i] = sc.nextInt();
    }
    System.out.println(dfs(h));
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] h = new int[n]; h new int[n] n for(int i = 0; i < n; i++) {
      h[i] = sc.nextInt();
    } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
      h[i] = sc.nextInt();
    } {
      h[i] = sc.nextInt();
    } h[i] = sc.nextInt() h[i] h i sc.nextInt() sc.nextInt sc System.out.println(dfs(h)) System.out.println System.out System System.out dfs(h) dfs h String[] args args public static int dfs(int[] hana) {
    int m = 100;
    for(int i = 0; i < hana.length; i++) {
      m = Math.min(m, hana[i]);
    }
    int ans = m;
    for(int i = 0; i < hana.length; i++) {
      hana[i] -= m;
    }
    int p = -1;
    int q = -1;
    int t = 0;
    for(int i = 0; i < hana.length; i++) {
      if(hana[i] > 0) {
        if(t == 0) {
          p = i;
          t = 1;
        } else {

        }
      } else {
        if(t == 1) {
          q = i - 1;
          t = 0;
          int[] hana2 = new int[q - p + 1];
          for(int j = 0; j < q - p + 1; j++) { 
            hana2[j] = hana[j + p];
          }
          ans += dfs(hana2);
          p = -1;
        }
      }
      if((i == hana.length - 1) && (p != -1)) {
        q = hana.length - 1;
        int[] hana2 = new int[q - p + 1];
        for(int j = 0; j < q - p + 1; j++) { 
          hana2[j] = hana[j + p];
        }
        ans += dfs(hana2);
      }
    }
    return ans;
  } dfs {
    int m = 100;
    for(int i = 0; i < hana.length; i++) {
      m = Math.min(m, hana[i]);
    }
    int ans = m;
    for(int i = 0; i < hana.length; i++) {
      hana[i] -= m;
    }
    int p = -1;
    int q = -1;
    int t = 0;
    for(int i = 0; i < hana.length; i++) {
      if(hana[i] > 0) {
        if(t == 0) {
          p = i;
          t = 1;
        } else {

        }
      } else {
        if(t == 1) {
          q = i - 1;
          t = 0;
          int[] hana2 = new int[q - p + 1];
          for(int j = 0; j < q - p + 1; j++) { 
            hana2[j] = hana[j + p];
          }
          ans += dfs(hana2);
          p = -1;
        }
      }
      if((i == hana.length - 1) && (p != -1)) {
        q = hana.length - 1;
        int[] hana2 = new int[q - p + 1];
        for(int j = 0; j < q - p + 1; j++) { 
          hana2[j] = hana[j + p];
        }
        ans += dfs(hana2);
      }
    }
    return ans;
  } int m = 100; m 100 for(int i = 0; i < hana.length; i++) {
      m = Math.min(m, hana[i]);
    } int i = 0; int i = 0; i 0 i < hana.length i hana.length hana hana.length i++ i++ i {
      m = Math.min(m, hana[i]);
    } {
      m = Math.min(m, hana[i]);
    } m = Math.min(m, hana[i]) m Math.min(m, hana[i]) Math.min Math m hana[i] hana i int ans = m; ans m for(int i = 0; i < hana.length; i++) {
      hana[i] -= m;
    } int i = 0; int i = 0; i 0 i < hana.length i hana.length hana hana.length i++ i++ i {
      hana[i] -= m;
    } {
      hana[i] -= m;
    } hana[i] -= m hana[i] hana i m int p = -1; p -1 1 int q = -1; q -1 1 int t = 0; t 0 for(int i = 0; i < hana.length; i++) {
      if(hana[i] > 0) {
        if(t == 0) {
          p = i;
          t = 1;
        } else {

        }
      } else {
        if(t == 1) {
          q = i - 1;
          t = 0;
          int[] hana2 = new int[q - p + 1];
          for(int j = 0; j < q - p + 1; j++) { 
            hana2[j] = hana[j + p];
          }
          ans += dfs(hana2);
          p = -1;
        }
      }
      if((i == hana.length - 1) && (p != -1)) {
        q = hana.length - 1;
        int[] hana2 = new int[q - p + 1];
        for(int j = 0; j < q - p + 1; j++) { 
          hana2[j] = hana[j + p];
        }
        ans += dfs(hana2);
      }
    } int i = 0; int i = 0; i 0 i < hana.length i hana.length hana hana.length i++ i++ i {
      if(hana[i] > 0) {
        if(t == 0) {
          p = i;
          t = 1;
        } else {

        }
      } else {
        if(t == 1) {
          q = i - 1;
          t = 0;
          int[] hana2 = new int[q - p + 1];
          for(int j = 0; j < q - p + 1; j++) { 
            hana2[j] = hana[j + p];
          }
          ans += dfs(hana2);
          p = -1;
        }
      }
      if((i == hana.length - 1) && (p != -1)) {
        q = hana.length - 1;
        int[] hana2 = new int[q - p + 1];
        for(int j = 0; j < q - p + 1; j++) { 
          hana2[j] = hana[j + p];
        }
        ans += dfs(hana2);
      }
    } {
      if(hana[i] > 0) {
        if(t == 0) {
          p = i;
          t = 1;
        } else {

        }
      } else {
        if(t == 1) {
          q = i - 1;
          t = 0;
          int[] hana2 = new int[q - p + 1];
          for(int j = 0; j < q - p + 1; j++) { 
            hana2[j] = hana[j + p];
          }
          ans += dfs(hana2);
          p = -1;
        }
      }
      if((i == hana.length - 1) && (p != -1)) {
        q = hana.length - 1;
        int[] hana2 = new int[q - p + 1];
        for(int j = 0; j < q - p + 1; j++) { 
          hana2[j] = hana[j + p];
        }
        ans += dfs(hana2);
      }
    } if(hana[i] > 0) {
        if(t == 0) {
          p = i;
          t = 1;
        } else {

        }
      } else {
        if(t == 1) {
          q = i - 1;
          t = 0;
          int[] hana2 = new int[q - p + 1];
          for(int j = 0; j < q - p + 1; j++) { 
            hana2[j] = hana[j + p];
          }
          ans += dfs(hana2);
          p = -1;
        }
      } hana[i] > 0 hana[i] hana i 0 {
        if(t == 0) {
          p = i;
          t = 1;
        } else {

        }
      } if(t == 0) {
          p = i;
          t = 1;
        } else {

        } t == 0 t 0 {
          p = i;
          t = 1;
        } p = i p i t = 1 t 1 {

        } {
        if(t == 1) {
          q = i - 1;
          t = 0;
          int[] hana2 = new int[q - p + 1];
          for(int j = 0; j < q - p + 1; j++) { 
            hana2[j] = hana[j + p];
          }
          ans += dfs(hana2);
          p = -1;
        }
      } if(t == 1) {
          q = i - 1;
          t = 0;
          int[] hana2 = new int[q - p + 1];
          for(int j = 0; j < q - p + 1; j++) { 
            hana2[j] = hana[j + p];
          }
          ans += dfs(hana2);
          p = -1;
        } t == 1 t 1 {
          q = i - 1;
          t = 0;
          int[] hana2 = new int[q - p + 1];
          for(int j = 0; j < q - p + 1; j++) { 
            hana2[j] = hana[j + p];
          }
          ans += dfs(hana2);
          p = -1;
        } q = i - 1 q i - 1 i 1 t = 0 t 0 int[] hana2 = new int[q - p + 1]; hana2 new int[q - p + 1] q - p + 1 q - p q p 1 for(int j = 0; j < q - p + 1; j++) { 
            hana2[j] = hana[j + p];
          } int j = 0; int j = 0; j 0 j < q - p + 1 j q - p + 1 q - p q p 1 j++ j++ j { 
            hana2[j] = hana[j + p];
          } { 
            hana2[j] = hana[j + p];
          } hana2[j] = hana[j + p] hana2[j] hana2 j hana[j + p] hana j + p j p ans += dfs(hana2) ans dfs(hana2) dfs hana2 p = -1 p -1 1 if((i == hana.length - 1) && (p != -1)) {
        q = hana.length - 1;
        int[] hana2 = new int[q - p + 1];
        for(int j = 0; j < q - p + 1; j++) { 
          hana2[j] = hana[j + p];
        }
        ans += dfs(hana2);
      } (i == hana.length - 1) && (p != -1) (i == hana.length - 1) i hana.length - 1 hana.length hana hana.length 1 (p != -1) p -1 1 {
        q = hana.length - 1;
        int[] hana2 = new int[q - p + 1];
        for(int j = 0; j < q - p + 1; j++) { 
          hana2[j] = hana[j + p];
        }
        ans += dfs(hana2);
      } q = hana.length - 1 q hana.length - 1 hana.length hana hana.length 1 int[] hana2 = new int[q - p + 1]; hana2 new int[q - p + 1] q - p + 1 q - p q p 1 for(int j = 0; j < q - p + 1; j++) { 
          hana2[j] = hana[j + p];
        } int j = 0; int j = 0; j 0 j < q - p + 1 j q - p + 1 q - p q p 1 j++ j++ j { 
          hana2[j] = hana[j + p];
        } { 
          hana2[j] = hana[j + p];
        } hana2[j] = hana[j + p] hana2[j] hana2 j hana[j + p] hana j + p j p ans += dfs(hana2) ans dfs(hana2) dfs hana2 return ans; ans int[] hana hana public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] h = new int[n];
    for(int i = 0; i < n; i++) {
      h[i] = sc.nextInt();
    }
    System.out.println(dfs(h));
  }

  public static int dfs(int[] hana) {
    int m = 100;
    for(int i = 0; i < hana.length; i++) {
      m = Math.min(m, hana[i]);
    }
    int ans = m;
    for(int i = 0; i < hana.length; i++) {
      hana[i] -= m;
    }
    int p = -1;
    int q = -1;
    int t = 0;
    for(int i = 0; i < hana.length; i++) {
      if(hana[i] > 0) {
        if(t == 0) {
          p = i;
          t = 1;
        } else {

        }
      } else {
        if(t == 1) {
          q = i - 1;
          t = 0;
          int[] hana2 = new int[q - p + 1];
          for(int j = 0; j < q - p + 1; j++) { 
            hana2[j] = hana[j + p];
          }
          ans += dfs(hana2);
          p = -1;
        }
      }
      if((i == hana.length - 1) && (p != -1)) {
        q = hana.length - 1;
        int[] hana2 = new int[q - p + 1];
        for(int j = 0; j < q - p + 1; j++) { 
          hana2[j] = hana[j + p];
        }
        ans += dfs(hana2);
      }
    }
    return ans;
  }
} public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] h = new int[n];
    for(int i = 0; i < n; i++) {
      h[i] = sc.nextInt();
    }
    System.out.println(dfs(h));
  }

  public static int dfs(int[] hana) {
    int m = 100;
    for(int i = 0; i < hana.length; i++) {
      m = Math.min(m, hana[i]);
    }
    int ans = m;
    for(int i = 0; i < hana.length; i++) {
      hana[i] -= m;
    }
    int p = -1;
    int q = -1;
    int t = 0;
    for(int i = 0; i < hana.length; i++) {
      if(hana[i] > 0) {
        if(t == 0) {
          p = i;
          t = 1;
        } else {

        }
      } else {
        if(t == 1) {
          q = i - 1;
          t = 0;
          int[] hana2 = new int[q - p + 1];
          for(int j = 0; j < q - p + 1; j++) { 
            hana2[j] = hana[j + p];
          }
          ans += dfs(hana2);
          p = -1;
        }
      }
      if((i == hana.length - 1) && (p != -1)) {
        q = hana.length - 1;
        int[] hana2 = new int[q - p + 1];
        for(int j = 0; j < q - p + 1; j++) { 
          hana2[j] = hana[j + p];
        }
        ans += dfs(hana2);
      }
    }
    return ans;
  }
} Main
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] h = new int[n];
    for(int i = 0; i < n; i++) {
      h[i] = sc.nextInt();
    }
    System.out.println(dfs(h));
  }

  public static int dfs(int[] hana) {
    int m = 100;
    for(int i = 0; i < hana.length; i++) {
      m = Math.min(m, hana[i]);
    }
    int ans = m;
    for(int i = 0; i < hana.length; i++) {
      hana[i] -= m;
    }
    int p = -1;
    int q = -1;
    int t = 0;
    for(int i = 0; i < hana.length; i++) {
      if(hana[i] > 0) {
        if(t == 0) {
          p = i;
          t = 1;
        } else {

        }
      } else {
        if(t == 1) {
          q = i - 1;
          t = 0;
          int[] hana2 = new int[q - p + 1];
          for(int j = 0; j < q - p + 1; j++) { 
            hana2[j] = hana[j + p];
          }
          ans += dfs(hana2);
          p = -1;
        }
      }
      if((i == hana.length - 1) && (p != -1)) {
        q = hana.length - 1;
        int[] hana2 = new int[q - p + 1];
        for(int j = 0; j < q - p + 1; j++) { 
          hana2[j] = hana[j + p];
        }
        ans += dfs(hana2);
      }
    }
    return ans;
  }
}
