import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] h = new int[n];
        int sum = 0;
        for(int i= 0; i < n; i++) {
        	h[i] = scan.nextInt();
        	sum += h[i];
        }
        int ans = 0;
        while(true) {
        	int temp = ans;
        	boolean f = false;
        	for(int i = 0; i < n; i++) {
        		if(f == false && h[i] != 0) {
        			f = true;
        			ans ++;
        		}
        		if(f) {
        			if(h[i] > 0) {
        				h[i]--;
        				sum--;
        			}else {
        				break;
        			}
        		}
        	}
        	if(temp == ans) {
        		break;
        	}
        }
        System.out.println(ans);
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] h = new int[n];
        int sum = 0;
        for(int i= 0; i < n; i++) {
        	h[i] = scan.nextInt();
        	sum += h[i];
        }
        int ans = 0;
        while(true) {
        	int temp = ans;
        	boolean f = false;
        	for(int i = 0; i < n; i++) {
        		if(f == false && h[i] != 0) {
        			f = true;
        			ans ++;
        		}
        		if(f) {
        			if(h[i] > 0) {
        				h[i]--;
        				sum--;
        			}else {
        				break;
        			}
        		}
        	}
        	if(temp == ans) {
        		break;
        	}
        }
        System.out.println(ans);
    }
} Main public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] h = new int[n];
        int sum = 0;
        for(int i= 0; i < n; i++) {
        	h[i] = scan.nextInt();
        	sum += h[i];
        }
        int ans = 0;
        while(true) {
        	int temp = ans;
        	boolean f = false;
        	for(int i = 0; i < n; i++) {
        		if(f == false && h[i] != 0) {
        			f = true;
        			ans ++;
        		}
        		if(f) {
        			if(h[i] > 0) {
        				h[i]--;
        				sum--;
        			}else {
        				break;
        			}
        		}
        	}
        	if(temp == ans) {
        		break;
        	}
        }
        System.out.println(ans);
    } main {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] h = new int[n];
        int sum = 0;
        for(int i= 0; i < n; i++) {
        	h[i] = scan.nextInt();
        	sum += h[i];
        }
        int ans = 0;
        while(true) {
        	int temp = ans;
        	boolean f = false;
        	for(int i = 0; i < n; i++) {
        		if(f == false && h[i] != 0) {
        			f = true;
        			ans ++;
        		}
        		if(f) {
        			if(h[i] > 0) {
        				h[i]--;
        				sum--;
        			}else {
        				break;
        			}
        		}
        	}
        	if(temp == ans) {
        		break;
        	}
        }
        System.out.println(ans);
    } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan int[] h = new int[n]; h new int[n] n int sum = 0; sum 0 for(int i= 0; i < n; i++) {
        	h[i] = scan.nextInt();
        	sum += h[i];
        } int i= 0; int i= 0; i 0 i < n i n i++ i++ i {
        	h[i] = scan.nextInt();
        	sum += h[i];
        } {
        	h[i] = scan.nextInt();
        	sum += h[i];
        } h[i] = scan.nextInt() h[i] h i scan.nextInt() scan.nextInt scan sum += h[i] sum h[i] h i int ans = 0; ans 0 while(true) {
        	int temp = ans;
        	boolean f = false;
        	for(int i = 0; i < n; i++) {
        		if(f == false && h[i] != 0) {
        			f = true;
        			ans ++;
        		}
        		if(f) {
        			if(h[i] > 0) {
        				h[i]--;
        				sum--;
        			}else {
        				break;
        			}
        		}
        	}
        	if(temp == ans) {
        		break;
        	}
        } true {
        	int temp = ans;
        	boolean f = false;
        	for(int i = 0; i < n; i++) {
        		if(f == false && h[i] != 0) {
        			f = true;
        			ans ++;
        		}
        		if(f) {
        			if(h[i] > 0) {
        				h[i]--;
        				sum--;
        			}else {
        				break;
        			}
        		}
        	}
        	if(temp == ans) {
        		break;
        	}
        } int temp = ans; temp ans boolean f = false; f false for(int i = 0; i < n; i++) {
        		if(f == false && h[i] != 0) {
        			f = true;
        			ans ++;
        		}
        		if(f) {
        			if(h[i] > 0) {
        				h[i]--;
        				sum--;
        			}else {
        				break;
        			}
        		}
        	} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
        		if(f == false && h[i] != 0) {
        			f = true;
        			ans ++;
        		}
        		if(f) {
        			if(h[i] > 0) {
        				h[i]--;
        				sum--;
        			}else {
        				break;
        			}
        		}
        	} {
        		if(f == false && h[i] != 0) {
        			f = true;
        			ans ++;
        		}
        		if(f) {
        			if(h[i] > 0) {
        				h[i]--;
        				sum--;
        			}else {
        				break;
        			}
        		}
        	} if(f == false && h[i] != 0) {
        			f = true;
        			ans ++;
        		} f == false && h[i] != 0 f == false f false h[i] != 0 h[i] h i 0 {
        			f = true;
        			ans ++;
        		} f = true f true ans ++ ans if(f) {
        			if(h[i] > 0) {
        				h[i]--;
        				sum--;
        			}else {
        				break;
        			}
        		} f {
        			if(h[i] > 0) {
        				h[i]--;
        				sum--;
        			}else {
        				break;
        			}
        		} if(h[i] > 0) {
        				h[i]--;
        				sum--;
        			}else {
        				break;
        			} h[i] > 0 h[i] h i 0 {
        				h[i]--;
        				sum--;
        			} h[i]-- h[i] h i sum-- sum {
        				break;
        			} break; if(temp == ans) {
        		break;
        	} temp == ans temp ans {
        		break;
        	} break; System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] h = new int[n];
        int sum = 0;
        for(int i= 0; i < n; i++) {
        	h[i] = scan.nextInt();
        	sum += h[i];
        }
        int ans = 0;
        while(true) {
        	int temp = ans;
        	boolean f = false;
        	for(int i = 0; i < n; i++) {
        		if(f == false && h[i] != 0) {
        			f = true;
        			ans ++;
        		}
        		if(f) {
        			if(h[i] > 0) {
        				h[i]--;
        				sum--;
        			}else {
        				break;
        			}
        		}
        	}
        	if(temp == ans) {
        		break;
        	}
        }
        System.out.println(ans);
    }
} public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] h = new int[n];
        int sum = 0;
        for(int i= 0; i < n; i++) {
        	h[i] = scan.nextInt();
        	sum += h[i];
        }
        int ans = 0;
        while(true) {
        	int temp = ans;
        	boolean f = false;
        	for(int i = 0; i < n; i++) {
        		if(f == false && h[i] != 0) {
        			f = true;
        			ans ++;
        		}
        		if(f) {
        			if(h[i] > 0) {
        				h[i]--;
        				sum--;
        			}else {
        				break;
        			}
        		}
        	}
        	if(temp == ans) {
        		break;
        	}
        }
        System.out.println(ans);
    }
} Main
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] h = new int[n];
        int sum = 0;
        for(int i= 0; i < n; i++) {
        	h[i] = scan.nextInt();
        	sum += h[i];
        }
        int ans = 0;
        while(true) {
        	int temp = ans;
        	boolean f = false;
        	for(int i = 0; i < n; i++) {
        		if(f == false && h[i] != 0) {
        			f = true;
        			ans ++;
        		}
        		if(f) {
        			if(h[i] > 0) {
        				h[i]--;
        				sum--;
        			}else {
        				break;
        			}
        		}
        	}
        	if(temp == ans) {
        		break;
        	}
        }
        System.out.println(ans);
    }
}