import java.util.Scanner;

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

        int ans = 0;
        for (int i = 0; i < n; i++) {
            if (h[i] == 0) {
                continue;
            }
            int max = h[i];
            for (int j = 0; j < max; j++) {
                ans++;
                for (int k = i; k < n; k++) {
                    if (h[k] > 0) {
                        h[k]--;
                    } else {
                        break;
                    }
                }
            }
        }
        System.out.println(ans);
    }

} import java.util.Scanner; Scanner 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();
        }
        sc.close();

        int ans = 0;
        for (int i = 0; i < n; i++) {
            if (h[i] == 0) {
                continue;
            }
            int max = h[i];
            for (int j = 0; j < max; j++) {
                ans++;
                for (int k = i; k < n; k++) {
                    if (h[k] > 0) {
                        h[k]--;
                    } else {
                        break;
                    }
                }
            }
        }
        System.out.println(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();
        }
        sc.close();

        int ans = 0;
        for (int i = 0; i < n; i++) {
            if (h[i] == 0) {
                continue;
            }
            int max = h[i];
            for (int j = 0; j < max; j++) {
                ans++;
                for (int k = i; k < n; k++) {
                    if (h[k] > 0) {
                        h[k]--;
                    } else {
                        break;
                    }
                }
            }
        }
        System.out.println(ans);
    } 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();
        }
        sc.close();

        int ans = 0;
        for (int i = 0; i < n; i++) {
            if (h[i] == 0) {
                continue;
            }
            int max = h[i];
            for (int j = 0; j < max; j++) {
                ans++;
                for (int k = i; k < n; k++) {
                    if (h[k] > 0) {
                        h[k]--;
                    } else {
                        break;
                    }
                }
            }
        }
        System.out.println(ans);
    } 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 sc.close() sc.close sc int ans = 0; ans 0 for (int i = 0; i < n; i++) {
            if (h[i] == 0) {
                continue;
            }
            int max = h[i];
            for (int j = 0; j < max; j++) {
                ans++;
                for (int k = i; k < n; k++) {
                    if (h[k] > 0) {
                        h[k]--;
                    } else {
                        break;
                    }
                }
            }
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            if (h[i] == 0) {
                continue;
            }
            int max = h[i];
            for (int j = 0; j < max; j++) {
                ans++;
                for (int k = i; k < n; k++) {
                    if (h[k] > 0) {
                        h[k]--;
                    } else {
                        break;
                    }
                }
            }
        } {
            if (h[i] == 0) {
                continue;
            }
            int max = h[i];
            for (int j = 0; j < max; j++) {
                ans++;
                for (int k = i; k < n; k++) {
                    if (h[k] > 0) {
                        h[k]--;
                    } else {
                        break;
                    }
                }
            }
        } if (h[i] == 0) {
                continue;
            } h[i] == 0 h[i] h i 0 {
                continue;
            } continue; int max = h[i]; max h[i] h i for (int j = 0; j < max; j++) {
                ans++;
                for (int k = i; k < n; k++) {
                    if (h[k] > 0) {
                        h[k]--;
                    } else {
                        break;
                    }
                }
            } int j = 0; int j = 0; j 0 j < max j max j++ j++ j {
                ans++;
                for (int k = i; k < n; k++) {
                    if (h[k] > 0) {
                        h[k]--;
                    } else {
                        break;
                    }
                }
            } {
                ans++;
                for (int k = i; k < n; k++) {
                    if (h[k] > 0) {
                        h[k]--;
                    } else {
                        break;
                    }
                }
            } ans++ ans for (int k = i; k < n; k++) {
                    if (h[k] > 0) {
                        h[k]--;
                    } else {
                        break;
                    }
                } int k = i; int k = i; k i k < n k n k++ k++ k {
                    if (h[k] > 0) {
                        h[k]--;
                    } else {
                        break;
                    }
                } {
                    if (h[k] > 0) {
                        h[k]--;
                    } else {
                        break;
                    }
                } if (h[k] > 0) {
                        h[k]--;
                    } else {
                        break;
                    } h[k] > 0 h[k] h k 0 {
                        h[k]--;
                    } h[k]-- h[k] h k {
                        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 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();
        }
        sc.close();

        int ans = 0;
        for (int i = 0; i < n; i++) {
            if (h[i] == 0) {
                continue;
            }
            int max = h[i];
            for (int j = 0; j < max; j++) {
                ans++;
                for (int k = i; k < n; k++) {
                    if (h[k] > 0) {
                        h[k]--;
                    } else {
                        break;
                    }
                }
            }
        }
        System.out.println(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();
        }
        sc.close();

        int ans = 0;
        for (int i = 0; i < n; i++) {
            if (h[i] == 0) {
                continue;
            }
            int max = h[i];
            for (int j = 0; j < max; j++) {
                ans++;
                for (int k = i; k < n; k++) {
                    if (h[k] > 0) {
                        h[k]--;
                    } else {
                        break;
                    }
                }
            }
        }
        System.out.println(ans);
    }

} Main
import java.util.Scanner;

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

        int ans = 0;
        for (int i = 0; i < n; i++) {
            if (h[i] == 0) {
                continue;
            }
            int max = h[i];
            for (int j = 0; j < max; j++) {
                ans++;
                for (int k = i; k < n; k++) {
                    if (h[k] > 0) {
                        h[k]--;
                    } else {
                        break;
                    }
                }
            }
        }
        System.out.println(ans);
    }

}
