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();
        }

        int numWaterings = 0;
        boolean nonZeroTreeFound = true;
        while (nonZeroTreeFound) {
        	nonZeroTreeFound = false;
            boolean oldBunchOfTreesEnded = false;
            for (int i=0; i<n; i++) {
            	if (h[i] > 0) {
                	nonZeroTreeFound = true;
                    h[i]--;
                    oldBunchOfTreesEnded = false;
                } else {
                	if (nonZeroTreeFound && !oldBunchOfTreesEnded) {
                      oldBunchOfTreesEnded = true;
                      numWaterings++;
                    }
                }
            }
            if (nonZeroTreeFound && !oldBunchOfTreesEnded) {
            	numWaterings++;
            }
        }
        System.out.println(numWaterings);
    }
} 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();
        }

        int numWaterings = 0;
        boolean nonZeroTreeFound = true;
        while (nonZeroTreeFound) {
        	nonZeroTreeFound = false;
            boolean oldBunchOfTreesEnded = false;
            for (int i=0; i<n; i++) {
            	if (h[i] > 0) {
                	nonZeroTreeFound = true;
                    h[i]--;
                    oldBunchOfTreesEnded = false;
                } else {
                	if (nonZeroTreeFound && !oldBunchOfTreesEnded) {
                      oldBunchOfTreesEnded = true;
                      numWaterings++;
                    }
                }
            }
            if (nonZeroTreeFound && !oldBunchOfTreesEnded) {
            	numWaterings++;
            }
        }
        System.out.println(numWaterings);
    }
} 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();
        }

        int numWaterings = 0;
        boolean nonZeroTreeFound = true;
        while (nonZeroTreeFound) {
        	nonZeroTreeFound = false;
            boolean oldBunchOfTreesEnded = false;
            for (int i=0; i<n; i++) {
            	if (h[i] > 0) {
                	nonZeroTreeFound = true;
                    h[i]--;
                    oldBunchOfTreesEnded = false;
                } else {
                	if (nonZeroTreeFound && !oldBunchOfTreesEnded) {
                      oldBunchOfTreesEnded = true;
                      numWaterings++;
                    }
                }
            }
            if (nonZeroTreeFound && !oldBunchOfTreesEnded) {
            	numWaterings++;
            }
        }
        System.out.println(numWaterings);
    } 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();
        }

        int numWaterings = 0;
        boolean nonZeroTreeFound = true;
        while (nonZeroTreeFound) {
        	nonZeroTreeFound = false;
            boolean oldBunchOfTreesEnded = false;
            for (int i=0; i<n; i++) {
            	if (h[i] > 0) {
                	nonZeroTreeFound = true;
                    h[i]--;
                    oldBunchOfTreesEnded = false;
                } else {
                	if (nonZeroTreeFound && !oldBunchOfTreesEnded) {
                      oldBunchOfTreesEnded = true;
                      numWaterings++;
                    }
                }
            }
            if (nonZeroTreeFound && !oldBunchOfTreesEnded) {
            	numWaterings++;
            }
        }
        System.out.println(numWaterings);
    } 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 int numWaterings = 0; numWaterings 0 boolean nonZeroTreeFound = true; nonZeroTreeFound true while (nonZeroTreeFound) {
        	nonZeroTreeFound = false;
            boolean oldBunchOfTreesEnded = false;
            for (int i=0; i<n; i++) {
            	if (h[i] > 0) {
                	nonZeroTreeFound = true;
                    h[i]--;
                    oldBunchOfTreesEnded = false;
                } else {
                	if (nonZeroTreeFound && !oldBunchOfTreesEnded) {
                      oldBunchOfTreesEnded = true;
                      numWaterings++;
                    }
                }
            }
            if (nonZeroTreeFound && !oldBunchOfTreesEnded) {
            	numWaterings++;
            }
        } nonZeroTreeFound {
        	nonZeroTreeFound = false;
            boolean oldBunchOfTreesEnded = false;
            for (int i=0; i<n; i++) {
            	if (h[i] > 0) {
                	nonZeroTreeFound = true;
                    h[i]--;
                    oldBunchOfTreesEnded = false;
                } else {
                	if (nonZeroTreeFound && !oldBunchOfTreesEnded) {
                      oldBunchOfTreesEnded = true;
                      numWaterings++;
                    }
                }
            }
            if (nonZeroTreeFound && !oldBunchOfTreesEnded) {
            	numWaterings++;
            }
        } nonZeroTreeFound = false nonZeroTreeFound false boolean oldBunchOfTreesEnded = false; oldBunchOfTreesEnded false for (int i=0; i<n; i++) {
            	if (h[i] > 0) {
                	nonZeroTreeFound = true;
                    h[i]--;
                    oldBunchOfTreesEnded = false;
                } else {
                	if (nonZeroTreeFound && !oldBunchOfTreesEnded) {
                      oldBunchOfTreesEnded = true;
                      numWaterings++;
                    }
                }
            } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            	if (h[i] > 0) {
                	nonZeroTreeFound = true;
                    h[i]--;
                    oldBunchOfTreesEnded = false;
                } else {
                	if (nonZeroTreeFound && !oldBunchOfTreesEnded) {
                      oldBunchOfTreesEnded = true;
                      numWaterings++;
                    }
                }
            } {
            	if (h[i] > 0) {
                	nonZeroTreeFound = true;
                    h[i]--;
                    oldBunchOfTreesEnded = false;
                } else {
                	if (nonZeroTreeFound && !oldBunchOfTreesEnded) {
                      oldBunchOfTreesEnded = true;
                      numWaterings++;
                    }
                }
            } if (h[i] > 0) {
                	nonZeroTreeFound = true;
                    h[i]--;
                    oldBunchOfTreesEnded = false;
                } else {
                	if (nonZeroTreeFound && !oldBunchOfTreesEnded) {
                      oldBunchOfTreesEnded = true;
                      numWaterings++;
                    }
                } h[i] > 0 h[i] h i 0 {
                	nonZeroTreeFound = true;
                    h[i]--;
                    oldBunchOfTreesEnded = false;
                } nonZeroTreeFound = true nonZeroTreeFound true h[i]-- h[i] h i oldBunchOfTreesEnded = false oldBunchOfTreesEnded false {
                	if (nonZeroTreeFound && !oldBunchOfTreesEnded) {
                      oldBunchOfTreesEnded = true;
                      numWaterings++;
                    }
                } if (nonZeroTreeFound && !oldBunchOfTreesEnded) {
                      oldBunchOfTreesEnded = true;
                      numWaterings++;
                    } nonZeroTreeFound && !oldBunchOfTreesEnded nonZeroTreeFound !oldBunchOfTreesEnded oldBunchOfTreesEnded {
                      oldBunchOfTreesEnded = true;
                      numWaterings++;
                    } oldBunchOfTreesEnded = true oldBunchOfTreesEnded true numWaterings++ numWaterings if (nonZeroTreeFound && !oldBunchOfTreesEnded) {
            	numWaterings++;
            } nonZeroTreeFound && !oldBunchOfTreesEnded nonZeroTreeFound !oldBunchOfTreesEnded oldBunchOfTreesEnded {
            	numWaterings++;
            } numWaterings++ numWaterings System.out.println(numWaterings) System.out.println System.out System System.out numWaterings String[] args args 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();
        }

        int numWaterings = 0;
        boolean nonZeroTreeFound = true;
        while (nonZeroTreeFound) {
        	nonZeroTreeFound = false;
            boolean oldBunchOfTreesEnded = false;
            for (int i=0; i<n; i++) {
            	if (h[i] > 0) {
                	nonZeroTreeFound = true;
                    h[i]--;
                    oldBunchOfTreesEnded = false;
                } else {
                	if (nonZeroTreeFound && !oldBunchOfTreesEnded) {
                      oldBunchOfTreesEnded = true;
                      numWaterings++;
                    }
                }
            }
            if (nonZeroTreeFound && !oldBunchOfTreesEnded) {
            	numWaterings++;
            }
        }
        System.out.println(numWaterings);
    }
} 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();
        }

        int numWaterings = 0;
        boolean nonZeroTreeFound = true;
        while (nonZeroTreeFound) {
        	nonZeroTreeFound = false;
            boolean oldBunchOfTreesEnded = false;
            for (int i=0; i<n; i++) {
            	if (h[i] > 0) {
                	nonZeroTreeFound = true;
                    h[i]--;
                    oldBunchOfTreesEnded = false;
                } else {
                	if (nonZeroTreeFound && !oldBunchOfTreesEnded) {
                      oldBunchOfTreesEnded = true;
                      numWaterings++;
                    }
                }
            }
            if (nonZeroTreeFound && !oldBunchOfTreesEnded) {
            	numWaterings++;
            }
        }
        System.out.println(numWaterings);
    }
} 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();
        }

        int numWaterings = 0;
        boolean nonZeroTreeFound = true;
        while (nonZeroTreeFound) {
        	nonZeroTreeFound = false;
            boolean oldBunchOfTreesEnded = false;
            for (int i=0; i<n; i++) {
            	if (h[i] > 0) {
                	nonZeroTreeFound = true;
                    h[i]--;
                    oldBunchOfTreesEnded = false;
                } else {
                	if (nonZeroTreeFound && !oldBunchOfTreesEnded) {
                      oldBunchOfTreesEnded = true;
                      numWaterings++;
                    }
                }
            }
            if (nonZeroTreeFound && !oldBunchOfTreesEnded) {
            	numWaterings++;
            }
        }
        System.out.println(numWaterings);
    }
}
