
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] heights = new int[n];
        for (int i = 0; i < n; i++) {
            heights[i] = sc.nextInt();
        }

        System.out.println(minWateringMoves(heights));
    }

    static int minWateringMoves(int... heights) {
        int moves = heights[0];
        for (int i = 1; i < heights.length; i++) {
            int diff = heights[i] - heights[i - 1];
            if (diff > 0) {
                moves += diff;
            }
        }
        return moves;
    }

} 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[] heights = new int[n];
        for (int i = 0; i < n; i++) {
            heights[i] = sc.nextInt();
        }

        System.out.println(minWateringMoves(heights));
    }

    static int minWateringMoves(int... heights) {
        int moves = heights[0];
        for (int i = 1; i < heights.length; i++) {
            int diff = heights[i] - heights[i - 1];
            if (diff > 0) {
                moves += diff;
            }
        }
        return moves;
    }

} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] heights = new int[n];
        for (int i = 0; i < n; i++) {
            heights[i] = sc.nextInt();
        }

        System.out.println(minWateringMoves(heights));
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] heights = new int[n];
        for (int i = 0; i < n; i++) {
            heights[i] = sc.nextInt();
        }

        System.out.println(minWateringMoves(heights));
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] heights = new int[n]; heights new int[n] n for (int i = 0; i < n; i++) {
            heights[i] = sc.nextInt();
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            heights[i] = sc.nextInt();
        } {
            heights[i] = sc.nextInt();
        } heights[i] = sc.nextInt() heights[i] heights i sc.nextInt() sc.nextInt sc System.out.println(minWateringMoves(heights)) System.out.println System.out System System.out minWateringMoves(heights) minWateringMoves heights String[] args args static int minWateringMoves(int... heights) {
        int moves = heights[0];
        for (int i = 1; i < heights.length; i++) {
            int diff = heights[i] - heights[i - 1];
            if (diff > 0) {
                moves += diff;
            }
        }
        return moves;
    } minWateringMoves {
        int moves = heights[0];
        for (int i = 1; i < heights.length; i++) {
            int diff = heights[i] - heights[i - 1];
            if (diff > 0) {
                moves += diff;
            }
        }
        return moves;
    } int moves = heights[0]; moves heights[0] heights 0 for (int i = 1; i < heights.length; i++) {
            int diff = heights[i] - heights[i - 1];
            if (diff > 0) {
                moves += diff;
            }
        } int i = 1; int i = 1; i 1 i < heights.length i heights.length heights heights.length i++ i++ i {
            int diff = heights[i] - heights[i - 1];
            if (diff > 0) {
                moves += diff;
            }
        } {
            int diff = heights[i] - heights[i - 1];
            if (diff > 0) {
                moves += diff;
            }
        } int diff = heights[i] - heights[i - 1]; diff heights[i] - heights[i - 1] heights[i] heights i heights[i - 1] heights i - 1 i 1 if (diff > 0) {
                moves += diff;
            } diff > 0 diff 0 {
                moves += diff;
            } moves += diff moves diff return moves; moves int... heights heights public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] heights = new int[n];
        for (int i = 0; i < n; i++) {
            heights[i] = sc.nextInt();
        }

        System.out.println(minWateringMoves(heights));
    }

    static int minWateringMoves(int... heights) {
        int moves = heights[0];
        for (int i = 1; i < heights.length; i++) {
            int diff = heights[i] - heights[i - 1];
            if (diff > 0) {
                moves += diff;
            }
        }
        return moves;
    }

} public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] heights = new int[n];
        for (int i = 0; i < n; i++) {
            heights[i] = sc.nextInt();
        }

        System.out.println(minWateringMoves(heights));
    }

    static int minWateringMoves(int... heights) {
        int moves = heights[0];
        for (int i = 1; i < heights.length; i++) {
            int diff = heights[i] - heights[i - 1];
            if (diff > 0) {
                moves += diff;
            }
        }
        return moves;
    }

} 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[] heights = new int[n];
        for (int i = 0; i < n; i++) {
            heights[i] = sc.nextInt();
        }

        System.out.println(minWateringMoves(heights));
    }

    static int minWateringMoves(int... heights) {
        int moves = heights[0];
        for (int i = 1; i < heights.length; i++) {
            int diff = heights[i] - heights[i - 1];
            if (diff > 0) {
                moves += diff;
            }
        }
        return moves;
    }

}
