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

        int cnt = 0;
        while (true) {
            int l = n;
            int r = n-1;

            for (int i = 0; i < n; i++) {
                if (h[i] > 0) {
                    l = Math.min(l, i);
                } else if (l < i) {
                    r = i-1;
                    break;
                }
            }

            if (l == n)
                break;

            int min = 110;
            for (int i = l; i <= r; i++) {
                min = Math.min(min, h[i]);
            }
            for (int i = l; i <= r; i++) {
                h[i] -= min;
            }
            cnt += min;
        }

        System.out.println(cnt);
    }
} 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();
        }

        int cnt = 0;
        while (true) {
            int l = n;
            int r = n-1;

            for (int i = 0; i < n; i++) {
                if (h[i] > 0) {
                    l = Math.min(l, i);
                } else if (l < i) {
                    r = i-1;
                    break;
                }
            }

            if (l == n)
                break;

            int min = 110;
            for (int i = l; i <= r; i++) {
                min = Math.min(min, h[i]);
            }
            for (int i = l; i <= r; i++) {
                h[i] -= min;
            }
            cnt += min;
        }

        System.out.println(cnt);
    }
} 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 cnt = 0;
        while (true) {
            int l = n;
            int r = n-1;

            for (int i = 0; i < n; i++) {
                if (h[i] > 0) {
                    l = Math.min(l, i);
                } else if (l < i) {
                    r = i-1;
                    break;
                }
            }

            if (l == n)
                break;

            int min = 110;
            for (int i = l; i <= r; i++) {
                min = Math.min(min, h[i]);
            }
            for (int i = l; i <= r; i++) {
                h[i] -= min;
            }
            cnt += min;
        }

        System.out.println(cnt);
    } 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 cnt = 0;
        while (true) {
            int l = n;
            int r = n-1;

            for (int i = 0; i < n; i++) {
                if (h[i] > 0) {
                    l = Math.min(l, i);
                } else if (l < i) {
                    r = i-1;
                    break;
                }
            }

            if (l == n)
                break;

            int min = 110;
            for (int i = l; i <= r; i++) {
                min = Math.min(min, h[i]);
            }
            for (int i = l; i <= r; i++) {
                h[i] -= min;
            }
            cnt += min;
        }

        System.out.println(cnt);
    } 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 cnt = 0; cnt 0 while (true) {
            int l = n;
            int r = n-1;

            for (int i = 0; i < n; i++) {
                if (h[i] > 0) {
                    l = Math.min(l, i);
                } else if (l < i) {
                    r = i-1;
                    break;
                }
            }

            if (l == n)
                break;

            int min = 110;
            for (int i = l; i <= r; i++) {
                min = Math.min(min, h[i]);
            }
            for (int i = l; i <= r; i++) {
                h[i] -= min;
            }
            cnt += min;
        } true {
            int l = n;
            int r = n-1;

            for (int i = 0; i < n; i++) {
                if (h[i] > 0) {
                    l = Math.min(l, i);
                } else if (l < i) {
                    r = i-1;
                    break;
                }
            }

            if (l == n)
                break;

            int min = 110;
            for (int i = l; i <= r; i++) {
                min = Math.min(min, h[i]);
            }
            for (int i = l; i <= r; i++) {
                h[i] -= min;
            }
            cnt += min;
        } int l = n; l n int r = n-1; r n-1 n 1 for (int i = 0; i < n; i++) {
                if (h[i] > 0) {
                    l = Math.min(l, i);
                } else if (l < i) {
                    r = i-1;
                    break;
                }
            } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
                if (h[i] > 0) {
                    l = Math.min(l, i);
                } else if (l < i) {
                    r = i-1;
                    break;
                }
            } {
                if (h[i] > 0) {
                    l = Math.min(l, i);
                } else if (l < i) {
                    r = i-1;
                    break;
                }
            } if (h[i] > 0) {
                    l = Math.min(l, i);
                } else if (l < i) {
                    r = i-1;
                    break;
                } h[i] > 0 h[i] h i 0 {
                    l = Math.min(l, i);
                } l = Math.min(l, i) l Math.min(l, i) Math.min Math l i if (l < i) {
                    r = i-1;
                    break;
                } l < i l i {
                    r = i-1;
                    break;
                } r = i-1 r i-1 i 1 break; if (l == n)
                break; l == n l n break; int min = 110; min 110 for (int i = l; i <= r; i++) {
                min = Math.min(min, h[i]);
            } int i = l; int i = l; i l i <= r i r i++ i++ i {
                min = Math.min(min, h[i]);
            } {
                min = Math.min(min, h[i]);
            } min = Math.min(min, h[i]) min Math.min(min, h[i]) Math.min Math min h[i] h i for (int i = l; i <= r; i++) {
                h[i] -= min;
            } int i = l; int i = l; i l i <= r i r i++ i++ i {
                h[i] -= min;
            } {
                h[i] -= min;
            } h[i] -= min h[i] h i min cnt += min cnt min System.out.println(cnt) System.out.println System.out System System.out cnt 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 cnt = 0;
        while (true) {
            int l = n;
            int r = n-1;

            for (int i = 0; i < n; i++) {
                if (h[i] > 0) {
                    l = Math.min(l, i);
                } else if (l < i) {
                    r = i-1;
                    break;
                }
            }

            if (l == n)
                break;

            int min = 110;
            for (int i = l; i <= r; i++) {
                min = Math.min(min, h[i]);
            }
            for (int i = l; i <= r; i++) {
                h[i] -= min;
            }
            cnt += min;
        }

        System.out.println(cnt);
    }
} 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 cnt = 0;
        while (true) {
            int l = n;
            int r = n-1;

            for (int i = 0; i < n; i++) {
                if (h[i] > 0) {
                    l = Math.min(l, i);
                } else if (l < i) {
                    r = i-1;
                    break;
                }
            }

            if (l == n)
                break;

            int min = 110;
            for (int i = l; i <= r; i++) {
                min = Math.min(min, h[i]);
            }
            for (int i = l; i <= r; i++) {
                h[i] -= min;
            }
            cnt += min;
        }

        System.out.println(cnt);
    }
} 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();
        }

        int cnt = 0;
        while (true) {
            int l = n;
            int r = n-1;

            for (int i = 0; i < n; i++) {
                if (h[i] > 0) {
                    l = Math.min(l, i);
                } else if (l < i) {
                    r = i-1;
                    break;
                }
            }

            if (l == n)
                break;

            int min = 110;
            for (int i = l; i <= r; i++) {
                min = Math.min(min, h[i]);
            }
            for (int i = l; i <= r; i++) {
                h[i] -= min;
            }
            cnt += min;
        }

        System.out.println(cnt);
    }
}
