

import java.util.Scanner;

public class Main {

	public static void main(String args[])
	{
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();
		int ar[]=new int[n];
		
		int ans=0;
		int pre=0;
		int cur;
		
		for(int i=0;i<n;i++)
		{
			int curr=scan.nextInt();
			if(pre>curr)
			{
				ans+=pre-curr;
			}
			pre=curr;
		}
		ans+=pre;
		System.out.println(ans);
	}
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String args[])
	{
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();
		int ar[]=new int[n];
		
		int ans=0;
		int pre=0;
		int cur;
		
		for(int i=0;i<n;i++)
		{
			int curr=scan.nextInt();
			if(pre>curr)
			{
				ans+=pre-curr;
			}
			pre=curr;
		}
		ans+=pre;
		System.out.println(ans);
	}
} Main public static void main(String args[])
	{
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();
		int ar[]=new int[n];
		
		int ans=0;
		int pre=0;
		int cur;
		
		for(int i=0;i<n;i++)
		{
			int curr=scan.nextInt();
			if(pre>curr)
			{
				ans+=pre-curr;
			}
			pre=curr;
		}
		ans+=pre;
		System.out.println(ans);
	} main {
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();
		int ar[]=new int[n];
		
		int ans=0;
		int pre=0;
		int cur;
		
		for(int i=0;i<n;i++)
		{
			int curr=scan.nextInt();
			if(pre>curr)
			{
				ans+=pre-curr;
			}
			pre=curr;
		}
		ans+=pre;
		System.out.println(ans);
	} Scanner scan=new Scanner(System.in); scan new Scanner(System.in) int n=scan.nextInt(); n scan.nextInt() scan.nextInt scan int ar[]=new int[n]; ar new int[n] n int ans=0; ans 0 int pre=0; pre 0 int cur; cur for(int i=0;i<n;i++)
		{
			int curr=scan.nextInt();
			if(pre>curr)
			{
				ans+=pre-curr;
			}
			pre=curr;
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			int curr=scan.nextInt();
			if(pre>curr)
			{
				ans+=pre-curr;
			}
			pre=curr;
		} {
			int curr=scan.nextInt();
			if(pre>curr)
			{
				ans+=pre-curr;
			}
			pre=curr;
		} int curr=scan.nextInt(); curr scan.nextInt() scan.nextInt scan if(pre>curr)
			{
				ans+=pre-curr;
			} pre>curr pre curr {
				ans+=pre-curr;
			} ans+=pre-curr ans pre-curr pre curr pre=curr pre curr ans+=pre ans pre 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 scan=new Scanner(System.in);
		int n=scan.nextInt();
		int ar[]=new int[n];
		
		int ans=0;
		int pre=0;
		int cur;
		
		for(int i=0;i<n;i++)
		{
			int curr=scan.nextInt();
			if(pre>curr)
			{
				ans+=pre-curr;
			}
			pre=curr;
		}
		ans+=pre;
		System.out.println(ans);
	}
} public class Main {

	public static void main(String args[])
	{
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();
		int ar[]=new int[n];
		
		int ans=0;
		int pre=0;
		int cur;
		
		for(int i=0;i<n;i++)
		{
			int curr=scan.nextInt();
			if(pre>curr)
			{
				ans+=pre-curr;
			}
			pre=curr;
		}
		ans+=pre;
		System.out.println(ans);
	}
} Main


import java.util.Scanner;

public class Main {

	public static void main(String args[])
	{
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();
		int ar[]=new int[n];
		
		int ans=0;
		int pre=0;
		int cur;
		
		for(int i=0;i<n;i++)
		{
			int curr=scan.nextInt();
			if(pre>curr)
			{
				ans+=pre-curr;
			}
			pre=curr;
		}
		ans+=pre;
		System.out.println(ans);
	}
}
