import java.util.*;

public class Main {
    public static void main(String[] args) {
        @SuppressWarnings("resource")
        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[] hi = new int[N];
        int status = 0;//0:none 1:start 2:end
        int result = 0;
        boolean judged = false;
        while ( !equal(hi, h)) {
            for (int i = 0; i < N; i++) {
                if (status == 0 && hi[i] < h[i] && !judged) {
                    status = 1;
                    result++;
                    hi[i]++;
                    //System.out.println(i + " a");
                    judged = true;
                }
                if (status == 1 && hi[i] < h[i] && !judged) {
                    hi[i]++;
                    //System.out.println(i + "b");
                    judged = true;
                }
                if (status == 1 && hi[i] >= h[i] && !judged) {
                    status = 2;
                    //System.out.println(i + "c");
                    judged = true;
                }
                judged = false;
                //System.out.println(result);
            }
            status = 0;
            //System.out.println(result);
        }
        System.out.println(result);
    }

    static boolean equal(int[] a, int[] b) {
        boolean result = true;
        for (int i = 0; i < a.length; i++) {
            if (a[i] != b[i]) {
                result = false;
                break;
            }
            //System.out.print(a[i] + " ");
        }
        //System.out.println(result);
        return result;
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
        @SuppressWarnings("resource")
        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[] hi = new int[N];
        int status = 0;//0:none 1:start 2:end
        int result = 0;
        boolean judged = false;
        while ( !equal(hi, h)) {
            for (int i = 0; i < N; i++) {
                if (status == 0 && hi[i] < h[i] && !judged) {
                    status = 1;
                    result++;
                    hi[i]++;
                    //System.out.println(i + " a");
                    judged = true;
                }
                if (status == 1 && hi[i] < h[i] && !judged) {
                    hi[i]++;
                    //System.out.println(i + "b");
                    judged = true;
                }
                if (status == 1 && hi[i] >= h[i] && !judged) {
                    status = 2;
                    //System.out.println(i + "c");
                    judged = true;
                }
                judged = false;
                //System.out.println(result);
            }
            status = 0;
            //System.out.println(result);
        }
        System.out.println(result);
    }

    static boolean equal(int[] a, int[] b) {
        boolean result = true;
        for (int i = 0; i < a.length; i++) {
            if (a[i] != b[i]) {
                result = false;
                break;
            }
            //System.out.print(a[i] + " ");
        }
        //System.out.println(result);
        return result;
    }
} Main public static void main(String[] args) {
        @SuppressWarnings("resource")
        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[] hi = new int[N];
        int status = 0;//0:none 1:start 2:end
        int result = 0;
        boolean judged = false;
        while ( !equal(hi, h)) {
            for (int i = 0; i < N; i++) {
                if (status == 0 && hi[i] < h[i] && !judged) {
                    status = 1;
                    result++;
                    hi[i]++;
                    //System.out.println(i + " a");
                    judged = true;
                }
                if (status == 1 && hi[i] < h[i] && !judged) {
                    hi[i]++;
                    //System.out.println(i + "b");
                    judged = true;
                }
                if (status == 1 && hi[i] >= h[i] && !judged) {
                    status = 2;
                    //System.out.println(i + "c");
                    judged = true;
                }
                judged = false;
                //System.out.println(result);
            }
            status = 0;
            //System.out.println(result);
        }
        System.out.println(result);
    } main {
        @SuppressWarnings("resource")
        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[] hi = new int[N];
        int status = 0;//0:none 1:start 2:end
        int result = 0;
        boolean judged = false;
        while ( !equal(hi, h)) {
            for (int i = 0; i < N; i++) {
                if (status == 0 && hi[i] < h[i] && !judged) {
                    status = 1;
                    result++;
                    hi[i]++;
                    //System.out.println(i + " a");
                    judged = true;
                }
                if (status == 1 && hi[i] < h[i] && !judged) {
                    hi[i]++;
                    //System.out.println(i + "b");
                    judged = true;
                }
                if (status == 1 && hi[i] >= h[i] && !judged) {
                    status = 2;
                    //System.out.println(i + "c");
                    judged = true;
                }
                judged = false;
                //System.out.println(result);
            }
            status = 0;
            //System.out.println(result);
        }
        System.out.println(result);
    } @SuppressWarnings("resource")
        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[] hi = new int[N]; hi new int[N] N int status = 0; status 0 int result = 0; result 0 boolean judged = false; judged false while ( !equal(hi, h)) {
            for (int i = 0; i < N; i++) {
                if (status == 0 && hi[i] < h[i] && !judged) {
                    status = 1;
                    result++;
                    hi[i]++;
                    //System.out.println(i + " a");
                    judged = true;
                }
                if (status == 1 && hi[i] < h[i] && !judged) {
                    hi[i]++;
                    //System.out.println(i + "b");
                    judged = true;
                }
                if (status == 1 && hi[i] >= h[i] && !judged) {
                    status = 2;
                    //System.out.println(i + "c");
                    judged = true;
                }
                judged = false;
                //System.out.println(result);
            }
            status = 0;
            //System.out.println(result);
        } !equal(hi, h) equal(hi, h) equal hi h {
            for (int i = 0; i < N; i++) {
                if (status == 0 && hi[i] < h[i] && !judged) {
                    status = 1;
                    result++;
                    hi[i]++;
                    //System.out.println(i + " a");
                    judged = true;
                }
                if (status == 1 && hi[i] < h[i] && !judged) {
                    hi[i]++;
                    //System.out.println(i + "b");
                    judged = true;
                }
                if (status == 1 && hi[i] >= h[i] && !judged) {
                    status = 2;
                    //System.out.println(i + "c");
                    judged = true;
                }
                judged = false;
                //System.out.println(result);
            }
            status = 0;
            //System.out.println(result);
        } for (int i = 0; i < N; i++) {
                if (status == 0 && hi[i] < h[i] && !judged) {
                    status = 1;
                    result++;
                    hi[i]++;
                    //System.out.println(i + " a");
                    judged = true;
                }
                if (status == 1 && hi[i] < h[i] && !judged) {
                    hi[i]++;
                    //System.out.println(i + "b");
                    judged = true;
                }
                if (status == 1 && hi[i] >= h[i] && !judged) {
                    status = 2;
                    //System.out.println(i + "c");
                    judged = true;
                }
                judged = false;
                //System.out.println(result);
            } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
                if (status == 0 && hi[i] < h[i] && !judged) {
                    status = 1;
                    result++;
                    hi[i]++;
                    //System.out.println(i + " a");
                    judged = true;
                }
                if (status == 1 && hi[i] < h[i] && !judged) {
                    hi[i]++;
                    //System.out.println(i + "b");
                    judged = true;
                }
                if (status == 1 && hi[i] >= h[i] && !judged) {
                    status = 2;
                    //System.out.println(i + "c");
                    judged = true;
                }
                judged = false;
                //System.out.println(result);
            } {
                if (status == 0 && hi[i] < h[i] && !judged) {
                    status = 1;
                    result++;
                    hi[i]++;
                    //System.out.println(i + " a");
                    judged = true;
                }
                if (status == 1 && hi[i] < h[i] && !judged) {
                    hi[i]++;
                    //System.out.println(i + "b");
                    judged = true;
                }
                if (status == 1 && hi[i] >= h[i] && !judged) {
                    status = 2;
                    //System.out.println(i + "c");
                    judged = true;
                }
                judged = false;
                //System.out.println(result);
            } if (status == 0 && hi[i] < h[i] && !judged) {
                    status = 1;
                    result++;
                    hi[i]++;
                    //System.out.println(i + " a");
                    judged = true;
                } status == 0 && hi[i] < h[i] && !judged status == 0 && hi[i] < h[i] && !judged status == 0 status 0 hi[i] < h[i] hi[i] hi i h[i] h i !judged judged {
                    status = 1;
                    result++;
                    hi[i]++;
                    //System.out.println(i + " a");
                    judged = true;
                } status = 1 status 1 result++ result hi[i]++ hi[i] hi i judged = true judged true if (status == 1 && hi[i] < h[i] && !judged) {
                    hi[i]++;
                    //System.out.println(i + "b");
                    judged = true;
                } status == 1 && hi[i] < h[i] && !judged status == 1 && hi[i] < h[i] && !judged status == 1 status 1 hi[i] < h[i] hi[i] hi i h[i] h i !judged judged {
                    hi[i]++;
                    //System.out.println(i + "b");
                    judged = true;
                } hi[i]++ hi[i] hi i judged = true judged true if (status == 1 && hi[i] >= h[i] && !judged) {
                    status = 2;
                    //System.out.println(i + "c");
                    judged = true;
                } status == 1 && hi[i] >= h[i] && !judged status == 1 && hi[i] >= h[i] && !judged status == 1 status 1 hi[i] >= h[i] hi[i] hi i h[i] h i !judged judged {
                    status = 2;
                    //System.out.println(i + "c");
                    judged = true;
                } status = 2 status 2 judged = true judged true judged = false judged false status = 0 status 0 System.out.println(result) System.out.println System.out System System.out result String[] args args static boolean equal(int[] a, int[] b) {
        boolean result = true;
        for (int i = 0; i < a.length; i++) {
            if (a[i] != b[i]) {
                result = false;
                break;
            }
            //System.out.print(a[i] + " ");
        }
        //System.out.println(result);
        return result;
    } equal {
        boolean result = true;
        for (int i = 0; i < a.length; i++) {
            if (a[i] != b[i]) {
                result = false;
                break;
            }
            //System.out.print(a[i] + " ");
        }
        //System.out.println(result);
        return result;
    } boolean result = true; result true for (int i = 0; i < a.length; i++) {
            if (a[i] != b[i]) {
                result = false;
                break;
            }
            //System.out.print(a[i] + " ");
        } int i = 0; int i = 0; i 0 i < a.length i a.length a a.length i++ i++ i {
            if (a[i] != b[i]) {
                result = false;
                break;
            }
            //System.out.print(a[i] + " ");
        } {
            if (a[i] != b[i]) {
                result = false;
                break;
            }
            //System.out.print(a[i] + " ");
        } if (a[i] != b[i]) {
                result = false;
                break;
            } a[i] != b[i] a[i] a i b[i] b i {
                result = false;
                break;
            } result = false result false break; return result; result int[] a a int[] b b public class Main {
    public static void main(String[] args) {
        @SuppressWarnings("resource")
        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[] hi = new int[N];
        int status = 0;//0:none 1:start 2:end
        int result = 0;
        boolean judged = false;
        while ( !equal(hi, h)) {
            for (int i = 0; i < N; i++) {
                if (status == 0 && hi[i] < h[i] && !judged) {
                    status = 1;
                    result++;
                    hi[i]++;
                    //System.out.println(i + " a");
                    judged = true;
                }
                if (status == 1 && hi[i] < h[i] && !judged) {
                    hi[i]++;
                    //System.out.println(i + "b");
                    judged = true;
                }
                if (status == 1 && hi[i] >= h[i] && !judged) {
                    status = 2;
                    //System.out.println(i + "c");
                    judged = true;
                }
                judged = false;
                //System.out.println(result);
            }
            status = 0;
            //System.out.println(result);
        }
        System.out.println(result);
    }

    static boolean equal(int[] a, int[] b) {
        boolean result = true;
        for (int i = 0; i < a.length; i++) {
            if (a[i] != b[i]) {
                result = false;
                break;
            }
            //System.out.print(a[i] + " ");
        }
        //System.out.println(result);
        return result;
    }
} public class Main {
    public static void main(String[] args) {
        @SuppressWarnings("resource")
        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[] hi = new int[N];
        int status = 0;//0:none 1:start 2:end
        int result = 0;
        boolean judged = false;
        while ( !equal(hi, h)) {
            for (int i = 0; i < N; i++) {
                if (status == 0 && hi[i] < h[i] && !judged) {
                    status = 1;
                    result++;
                    hi[i]++;
                    //System.out.println(i + " a");
                    judged = true;
                }
                if (status == 1 && hi[i] < h[i] && !judged) {
                    hi[i]++;
                    //System.out.println(i + "b");
                    judged = true;
                }
                if (status == 1 && hi[i] >= h[i] && !judged) {
                    status = 2;
                    //System.out.println(i + "c");
                    judged = true;
                }
                judged = false;
                //System.out.println(result);
            }
            status = 0;
            //System.out.println(result);
        }
        System.out.println(result);
    }

    static boolean equal(int[] a, int[] b) {
        boolean result = true;
        for (int i = 0; i < a.length; i++) {
            if (a[i] != b[i]) {
                result = false;
                break;
            }
            //System.out.print(a[i] + " ");
        }
        //System.out.println(result);
        return result;
    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args) {
        @SuppressWarnings("resource")
        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[] hi = new int[N];
        int status = 0;//0:none 1:start 2:end
        int result = 0;
        boolean judged = false;
        while ( !equal(hi, h)) {
            for (int i = 0; i < N; i++) {
                if (status == 0 && hi[i] < h[i] && !judged) {
                    status = 1;
                    result++;
                    hi[i]++;
                    //System.out.println(i + " a");
                    judged = true;
                }
                if (status == 1 && hi[i] < h[i] && !judged) {
                    hi[i]++;
                    //System.out.println(i + "b");
                    judged = true;
                }
                if (status == 1 && hi[i] >= h[i] && !judged) {
                    status = 2;
                    //System.out.println(i + "c");
                    judged = true;
                }
                judged = false;
                //System.out.println(result);
            }
            status = 0;
            //System.out.println(result);
        }
        System.out.println(result);
    }

    static boolean equal(int[] a, int[] b) {
        boolean result = true;
        for (int i = 0; i < a.length; i++) {
            if (a[i] != b[i]) {
                result = false;
                break;
            }
            //System.out.print(a[i] + " ");
        }
        //System.out.println(result);
        return result;
    }
}