
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();

        int[] nums = new int[N];
        for (int i = 0; i < N; i++) {
            nums[i] = sc.nextInt();
        }
        sc.close();
        System.out.println(garden(nums));
    }

   private static int garden(int nums[]) {
        int count = 0;
        for (int i = 0; i < nums.length - 1; i++) {
            if (nums[i] > nums[i + 1]) {
               count = count + (nums[i] - nums[i +1]);
            }
        }
        return count + nums[nums.length - 1];
    }

} 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[] nums = new int[N];
        for (int i = 0; i < N; i++) {
            nums[i] = sc.nextInt();
        }
        sc.close();
        System.out.println(garden(nums));
    }

   private static int garden(int nums[]) {
        int count = 0;
        for (int i = 0; i < nums.length - 1; i++) {
            if (nums[i] > nums[i + 1]) {
               count = count + (nums[i] - nums[i +1]);
            }
        }
        return count + nums[nums.length - 1];
    }

} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();

        int[] nums = new int[N];
        for (int i = 0; i < N; i++) {
            nums[i] = sc.nextInt();
        }
        sc.close();
        System.out.println(garden(nums));
    } main {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();

        int[] nums = new int[N];
        for (int i = 0; i < N; i++) {
            nums[i] = sc.nextInt();
        }
        sc.close();
        System.out.println(garden(nums));
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int[] nums = new int[N]; nums new int[N] N for (int i = 0; i < N; i++) {
            nums[i] = sc.nextInt();
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            nums[i] = sc.nextInt();
        } {
            nums[i] = sc.nextInt();
        } nums[i] = sc.nextInt() nums[i] nums i sc.nextInt() sc.nextInt sc sc.close() sc.close sc System.out.println(garden(nums)) System.out.println System.out System System.out garden(nums) garden nums String[] args args private static int garden(int nums[]) {
        int count = 0;
        for (int i = 0; i < nums.length - 1; i++) {
            if (nums[i] > nums[i + 1]) {
               count = count + (nums[i] - nums[i +1]);
            }
        }
        return count + nums[nums.length - 1];
    } garden {
        int count = 0;
        for (int i = 0; i < nums.length - 1; i++) {
            if (nums[i] > nums[i + 1]) {
               count = count + (nums[i] - nums[i +1]);
            }
        }
        return count + nums[nums.length - 1];
    } int count = 0; count 0 for (int i = 0; i < nums.length - 1; i++) {
            if (nums[i] > nums[i + 1]) {
               count = count + (nums[i] - nums[i +1]);
            }
        } int i = 0; int i = 0; i 0 i < nums.length - 1 i nums.length - 1 nums.length nums nums.length 1 i++ i++ i {
            if (nums[i] > nums[i + 1]) {
               count = count + (nums[i] - nums[i +1]);
            }
        } {
            if (nums[i] > nums[i + 1]) {
               count = count + (nums[i] - nums[i +1]);
            }
        } if (nums[i] > nums[i + 1]) {
               count = count + (nums[i] - nums[i +1]);
            } nums[i] > nums[i + 1] nums[i] nums i nums[i + 1] nums i + 1 i 1 {
               count = count + (nums[i] - nums[i +1]);
            } count = count + (nums[i] - nums[i +1]) count count + (nums[i] - nums[i +1]) count (nums[i] - nums[i +1]) nums[i] nums i nums[i +1] nums i +1 i 1 return count + nums[nums.length - 1]; count + nums[nums.length - 1] count nums[nums.length - 1] nums nums.length - 1 nums.length nums nums.length 1 int nums[] nums public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();

        int[] nums = new int[N];
        for (int i = 0; i < N; i++) {
            nums[i] = sc.nextInt();
        }
        sc.close();
        System.out.println(garden(nums));
    }

   private static int garden(int nums[]) {
        int count = 0;
        for (int i = 0; i < nums.length - 1; i++) {
            if (nums[i] > nums[i + 1]) {
               count = count + (nums[i] - nums[i +1]);
            }
        }
        return count + nums[nums.length - 1];
    }

} public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();

        int[] nums = new int[N];
        for (int i = 0; i < N; i++) {
            nums[i] = sc.nextInt();
        }
        sc.close();
        System.out.println(garden(nums));
    }

   private static int garden(int nums[]) {
        int count = 0;
        for (int i = 0; i < nums.length - 1; i++) {
            if (nums[i] > nums[i + 1]) {
               count = count + (nums[i] - nums[i +1]);
            }
        }
        return count + nums[nums.length - 1];
    }

} 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[] nums = new int[N];
        for (int i = 0; i < N; i++) {
            nums[i] = sc.nextInt();
        }
        sc.close();
        System.out.println(garden(nums));
    }

   private static int garden(int nums[]) {
        int count = 0;
        for (int i = 0; i < nums.length - 1; i++) {
            if (nums[i] > nums[i + 1]) {
               count = count + (nums[i] - nums[i +1]);
            }
        }
        return count + nums[nums.length - 1];
    }

}