import java.util.*;
class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int N = sc.nextInt();
	int[] h = new int[N];
	int hMax = 0;
	for(int i = 0; i<N; i++) {
	    h[i] = sc.nextInt();
	    hMax = Math.max(h[i], hMax);
	}

	int height = 0;
	int shima = 0;
	for(int k = 0; k<hMax; k++) {
	    boolean isConnect = false;
	    for(int i = 0; i<N; i++) {
		if(h[i]-height > 0 ) {
		    if(isConnect == false) shima++;
		    isConnect = true;
		}else {
		    isConnect = false;
		}
	    }
	    height++;
	}
	System.out.println(shima);
    }
} import java.util.*; util.* java class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int N = sc.nextInt();
	int[] h = new int[N];
	int hMax = 0;
	for(int i = 0; i<N; i++) {
	    h[i] = sc.nextInt();
	    hMax = Math.max(h[i], hMax);
	}

	int height = 0;
	int shima = 0;
	for(int k = 0; k<hMax; k++) {
	    boolean isConnect = false;
	    for(int i = 0; i<N; i++) {
		if(h[i]-height > 0 ) {
		    if(isConnect == false) shima++;
		    isConnect = true;
		}else {
		    isConnect = false;
		}
	    }
	    height++;
	}
	System.out.println(shima);
    }
} Main public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int N = sc.nextInt();
	int[] h = new int[N];
	int hMax = 0;
	for(int i = 0; i<N; i++) {
	    h[i] = sc.nextInt();
	    hMax = Math.max(h[i], hMax);
	}

	int height = 0;
	int shima = 0;
	for(int k = 0; k<hMax; k++) {
	    boolean isConnect = false;
	    for(int i = 0; i<N; i++) {
		if(h[i]-height > 0 ) {
		    if(isConnect == false) shima++;
		    isConnect = true;
		}else {
		    isConnect = false;
		}
	    }
	    height++;
	}
	System.out.println(shima);
    } main {
	Scanner sc = new Scanner(System.in);
	int N = sc.nextInt();
	int[] h = new int[N];
	int hMax = 0;
	for(int i = 0; i<N; i++) {
	    h[i] = sc.nextInt();
	    hMax = Math.max(h[i], hMax);
	}

	int height = 0;
	int shima = 0;
	for(int k = 0; k<hMax; k++) {
	    boolean isConnect = false;
	    for(int i = 0; i<N; i++) {
		if(h[i]-height > 0 ) {
		    if(isConnect == false) shima++;
		    isConnect = true;
		}else {
		    isConnect = false;
		}
	    }
	    height++;
	}
	System.out.println(shima);
    } 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 int hMax = 0; hMax 0 for(int i = 0; i<N; i++) {
	    h[i] = sc.nextInt();
	    hMax = Math.max(h[i], hMax);
	} int i = 0; int i = 0; i 0 i<N i N i++ i++ i {
	    h[i] = sc.nextInt();
	    hMax = Math.max(h[i], hMax);
	} {
	    h[i] = sc.nextInt();
	    hMax = Math.max(h[i], hMax);
	} h[i] = sc.nextInt() h[i] h i sc.nextInt() sc.nextInt sc hMax = Math.max(h[i], hMax) hMax Math.max(h[i], hMax) Math.max Math h[i] h i hMax int height = 0; height 0 int shima = 0; shima 0 for(int k = 0; k<hMax; k++) {
	    boolean isConnect = false;
	    for(int i = 0; i<N; i++) {
		if(h[i]-height > 0 ) {
		    if(isConnect == false) shima++;
		    isConnect = true;
		}else {
		    isConnect = false;
		}
	    }
	    height++;
	} int k = 0; int k = 0; k 0 k<hMax k hMax k++ k++ k {
	    boolean isConnect = false;
	    for(int i = 0; i<N; i++) {
		if(h[i]-height > 0 ) {
		    if(isConnect == false) shima++;
		    isConnect = true;
		}else {
		    isConnect = false;
		}
	    }
	    height++;
	} {
	    boolean isConnect = false;
	    for(int i = 0; i<N; i++) {
		if(h[i]-height > 0 ) {
		    if(isConnect == false) shima++;
		    isConnect = true;
		}else {
		    isConnect = false;
		}
	    }
	    height++;
	} boolean isConnect = false; isConnect false for(int i = 0; i<N; i++) {
		if(h[i]-height > 0 ) {
		    if(isConnect == false) shima++;
		    isConnect = true;
		}else {
		    isConnect = false;
		}
	    } int i = 0; int i = 0; i 0 i<N i N i++ i++ i {
		if(h[i]-height > 0 ) {
		    if(isConnect == false) shima++;
		    isConnect = true;
		}else {
		    isConnect = false;
		}
	    } {
		if(h[i]-height > 0 ) {
		    if(isConnect == false) shima++;
		    isConnect = true;
		}else {
		    isConnect = false;
		}
	    } if(h[i]-height > 0 ) {
		    if(isConnect == false) shima++;
		    isConnect = true;
		}else {
		    isConnect = false;
		} h[i]-height > 0 h[i]-height h[i] h i height 0 {
		    if(isConnect == false) shima++;
		    isConnect = true;
		} if(isConnect == false) shima++; isConnect == false isConnect false shima++ shima isConnect = true isConnect true {
		    isConnect = false;
		} isConnect = false isConnect false height++ height System.out.println(shima) System.out.println System.out System System.out shima String[] args args
import java.util.*;
class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int N = sc.nextInt();
	int[] h = new int[N];
	int hMax = 0;
	for(int i = 0; i<N; i++) {
	    h[i] = sc.nextInt();
	    hMax = Math.max(h[i], hMax);
	}

	int height = 0;
	int shima = 0;
	for(int k = 0; k<hMax; k++) {
	    boolean isConnect = false;
	    for(int i = 0; i<N; i++) {
		if(h[i]-height > 0 ) {
		    if(isConnect == false) shima++;
		    isConnect = true;
		}else {
		    isConnect = false;
		}
	    }
	    height++;
	}
	System.out.println(shima);
    }
}