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

class Main {

    // Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
    public static void main(String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);
        long N;
        N = sc.nextLong();
        long[] h = new long[(int)(N)];
        for(int i = 0 ; i < N ; i++){
                h[i] = sc.nextLong();
        }
        solve(N, h);
    }

    static void solve(long N, long[] h){
	int ans = 0;
	while(!isAllZero(h)) {
	    int left = 0;
	    while(left < h.length) {
		//System.out.println(Arrays.toString(h));
		int right = left;
		while(right < h.length && h[right] != 0) { right++; }
		if (left != right) { ans++; }
		for(int i = left; i < right; i++) {
		    h[i]--;
		}
		left = right + 1;
	    }
	}
	System.out.println(ans);
    }

    static boolean isAllZero(long[] h) {
	for(long i: h) {
	    if (i != 0) {
		return false;
	    }
	}
	return true;
    }
} import java.io.*; io.* java import java.util.*; util.* java class Main {

    // Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
    public static void main(String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);
        long N;
        N = sc.nextLong();
        long[] h = new long[(int)(N)];
        for(int i = 0 ; i < N ; i++){
                h[i] = sc.nextLong();
        }
        solve(N, h);
    }

    static void solve(long N, long[] h){
	int ans = 0;
	while(!isAllZero(h)) {
	    int left = 0;
	    while(left < h.length) {
		//System.out.println(Arrays.toString(h));
		int right = left;
		while(right < h.length && h[right] != 0) { right++; }
		if (left != right) { ans++; }
		for(int i = left; i < right; i++) {
		    h[i]--;
		}
		left = right + 1;
	    }
	}
	System.out.println(ans);
    }

    static boolean isAllZero(long[] h) {
	for(long i: h) {
	    if (i != 0) {
		return false;
	    }
	}
	return true;
    }
} Main // Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
    public static void main(String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);
        long N;
        N = sc.nextLong();
        long[] h = new long[(int)(N)];
        for(int i = 0 ; i < N ; i++){
                h[i] = sc.nextLong();
        }
        solve(N, h);
    } main {
        final Scanner sc = new Scanner(System.in);
        long N;
        N = sc.nextLong();
        long[] h = new long[(int)(N)];
        for(int i = 0 ; i < N ; i++){
                h[i] = sc.nextLong();
        }
        solve(N, h);
    } final Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long N; N N = sc.nextLong() N sc.nextLong() sc.nextLong sc long[] h = new long[(int)(N)]; h new long[(int)(N)] (int)(N) for(int i = 0 ; i < N ; i++){
                h[i] = sc.nextLong();
        } int i = 0 ; int i = 0 ; i 0 i < N i N i++ i++ i {
                h[i] = sc.nextLong();
        } {
                h[i] = sc.nextLong();
        } h[i] = sc.nextLong() h[i] h i sc.nextLong() sc.nextLong sc solve(N, h) solve N h String[] args args static void solve(long N, long[] h){
	int ans = 0;
	while(!isAllZero(h)) {
	    int left = 0;
	    while(left < h.length) {
		//System.out.println(Arrays.toString(h));
		int right = left;
		while(right < h.length && h[right] != 0) { right++; }
		if (left != right) { ans++; }
		for(int i = left; i < right; i++) {
		    h[i]--;
		}
		left = right + 1;
	    }
	}
	System.out.println(ans);
    } solve {
	int ans = 0;
	while(!isAllZero(h)) {
	    int left = 0;
	    while(left < h.length) {
		//System.out.println(Arrays.toString(h));
		int right = left;
		while(right < h.length && h[right] != 0) { right++; }
		if (left != right) { ans++; }
		for(int i = left; i < right; i++) {
		    h[i]--;
		}
		left = right + 1;
	    }
	}
	System.out.println(ans);
    } int ans = 0; ans 0 while(!isAllZero(h)) {
	    int left = 0;
	    while(left < h.length) {
		//System.out.println(Arrays.toString(h));
		int right = left;
		while(right < h.length && h[right] != 0) { right++; }
		if (left != right) { ans++; }
		for(int i = left; i < right; i++) {
		    h[i]--;
		}
		left = right + 1;
	    }
	} !isAllZero(h) isAllZero(h) isAllZero h {
	    int left = 0;
	    while(left < h.length) {
		//System.out.println(Arrays.toString(h));
		int right = left;
		while(right < h.length && h[right] != 0) { right++; }
		if (left != right) { ans++; }
		for(int i = left; i < right; i++) {
		    h[i]--;
		}
		left = right + 1;
	    }
	} int left = 0; left 0 while(left < h.length) {
		//System.out.println(Arrays.toString(h));
		int right = left;
		while(right < h.length && h[right] != 0) { right++; }
		if (left != right) { ans++; }
		for(int i = left; i < right; i++) {
		    h[i]--;
		}
		left = right + 1;
	    } left < h.length left h.length h h.length {
		//System.out.println(Arrays.toString(h));
		int right = left;
		while(right < h.length && h[right] != 0) { right++; }
		if (left != right) { ans++; }
		for(int i = left; i < right; i++) {
		    h[i]--;
		}
		left = right + 1;
	    } int right = left; right left while(right < h.length && h[right] != 0) { right++; } right < h.length && h[right] != 0 right < h.length right h.length h h.length h[right] != 0 h[right] h right 0 { right++; } right++ right if (left != right) { ans++; } left != right left right { ans++; } ans++ ans for(int i = left; i < right; i++) {
		    h[i]--;
		} int i = left; int i = left; i left i < right i right i++ i++ i {
		    h[i]--;
		} {
		    h[i]--;
		} h[i]-- h[i] h i left = right + 1 left right + 1 right 1 System.out.println(ans) System.out.println System.out System System.out ans long N N long[] h h static boolean isAllZero(long[] h) {
	for(long i: h) {
	    if (i != 0) {
		return false;
	    }
	}
	return true;
    } isAllZero {
	for(long i: h) {
	    if (i != 0) {
		return false;
	    }
	}
	return true;
    } for(long i: h) {
	    if (i != 0) {
		return false;
	    }
	} long i h {
	    if (i != 0) {
		return false;
	    }
	} {
	    if (i != 0) {
		return false;
	    }
	} if (i != 0) {
		return false;
	    } i != 0 i 0 {
		return false;
	    } return false; false return true; true long[] h h
import java.io.*;
import java.util.*;

class Main {

    // Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
    public static void main(String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);
        long N;
        N = sc.nextLong();
        long[] h = new long[(int)(N)];
        for(int i = 0 ; i < N ; i++){
                h[i] = sc.nextLong();
        }
        solve(N, h);
    }

    static void solve(long N, long[] h){
	int ans = 0;
	while(!isAllZero(h)) {
	    int left = 0;
	    while(left < h.length) {
		//System.out.println(Arrays.toString(h));
		int right = left;
		while(right < h.length && h[right] != 0) { right++; }
		if (left != right) { ans++; }
		for(int i = left; i < right; i++) {
		    h[i]--;
		}
		left = right + 1;
	    }
	}
	System.out.println(ans);
    }

    static boolean isAllZero(long[] h) {
	for(long i: h) {
	    if (i != 0) {
		return false;
	    }
	}
	return true;
    }
}
