import java.util.Scanner;

public class Main {

    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        Integer[] h = new Integer[n];
        int maxHeight = 0;
        for (int i = 0; i < n; i++) {
            h[i] = Integer.parseInt(sc.next());
            maxHeight = Math.max(maxHeight, h[i]);
        }

        int result = 0;
        for (int j = 0; j < maxHeight; j++) {
            boolean edgeFlag = true;
            for (int i = 0; i < n; i++) {
                if (h[i] > 0) {
                    h[i]--;
                    edgeFlag = false;
                } else if (!edgeFlag) {
                    result++;
                    edgeFlag = true;
                }
            }
            if (!edgeFlag) {
                result++;
            }
        }

        System.out.println(result);
    }
} import java.util.Scanner; Scanner java.util public class Main {

    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        Integer[] h = new Integer[n];
        int maxHeight = 0;
        for (int i = 0; i < n; i++) {
            h[i] = Integer.parseInt(sc.next());
            maxHeight = Math.max(maxHeight, h[i]);
        }

        int result = 0;
        for (int j = 0; j < maxHeight; j++) {
            boolean edgeFlag = true;
            for (int i = 0; i < n; i++) {
                if (h[i] > 0) {
                    h[i]--;
                    edgeFlag = false;
                } else if (!edgeFlag) {
                    result++;
                    edgeFlag = true;
                }
            }
            if (!edgeFlag) {
                result++;
            }
        }

        System.out.println(result);
    }
} Main public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        Integer[] h = new Integer[n];
        int maxHeight = 0;
        for (int i = 0; i < n; i++) {
            h[i] = Integer.parseInt(sc.next());
            maxHeight = Math.max(maxHeight, h[i]);
        }

        int result = 0;
        for (int j = 0; j < maxHeight; j++) {
            boolean edgeFlag = true;
            for (int i = 0; i < n; i++) {
                if (h[i] > 0) {
                    h[i]--;
                    edgeFlag = false;
                } else if (!edgeFlag) {
                    result++;
                    edgeFlag = true;
                }
            }
            if (!edgeFlag) {
                result++;
            }
        }

        System.out.println(result);
    } main {

        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        Integer[] h = new Integer[n];
        int maxHeight = 0;
        for (int i = 0; i < n; i++) {
            h[i] = Integer.parseInt(sc.next());
            maxHeight = Math.max(maxHeight, h[i]);
        }

        int result = 0;
        for (int j = 0; j < maxHeight; j++) {
            boolean edgeFlag = true;
            for (int i = 0; i < n; i++) {
                if (h[i] > 0) {
                    h[i]--;
                    edgeFlag = false;
                } else if (!edgeFlag) {
                    result++;
                    edgeFlag = true;
                }
            }
            if (!edgeFlag) {
                result++;
            }
        }

        System.out.println(result);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = Integer.parseInt(sc.next()); n Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc Integer[] h = new Integer[n]; h new Integer[n] n int maxHeight = 0; maxHeight 0 for (int i = 0; i < n; i++) {
            h[i] = Integer.parseInt(sc.next());
            maxHeight = Math.max(maxHeight, h[i]);
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            h[i] = Integer.parseInt(sc.next());
            maxHeight = Math.max(maxHeight, h[i]);
        } {
            h[i] = Integer.parseInt(sc.next());
            maxHeight = Math.max(maxHeight, h[i]);
        } h[i] = Integer.parseInt(sc.next()) h[i] h i Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc maxHeight = Math.max(maxHeight, h[i]) maxHeight Math.max(maxHeight, h[i]) Math.max Math maxHeight h[i] h i int result = 0; result 0 for (int j = 0; j < maxHeight; j++) {
            boolean edgeFlag = true;
            for (int i = 0; i < n; i++) {
                if (h[i] > 0) {
                    h[i]--;
                    edgeFlag = false;
                } else if (!edgeFlag) {
                    result++;
                    edgeFlag = true;
                }
            }
            if (!edgeFlag) {
                result++;
            }
        } int j = 0; int j = 0; j 0 j < maxHeight j maxHeight j++ j++ j {
            boolean edgeFlag = true;
            for (int i = 0; i < n; i++) {
                if (h[i] > 0) {
                    h[i]--;
                    edgeFlag = false;
                } else if (!edgeFlag) {
                    result++;
                    edgeFlag = true;
                }
            }
            if (!edgeFlag) {
                result++;
            }
        } {
            boolean edgeFlag = true;
            for (int i = 0; i < n; i++) {
                if (h[i] > 0) {
                    h[i]--;
                    edgeFlag = false;
                } else if (!edgeFlag) {
                    result++;
                    edgeFlag = true;
                }
            }
            if (!edgeFlag) {
                result++;
            }
        } boolean edgeFlag = true; edgeFlag true for (int i = 0; i < n; i++) {
                if (h[i] > 0) {
                    h[i]--;
                    edgeFlag = false;
                } else if (!edgeFlag) {
                    result++;
                    edgeFlag = true;
                }
            } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
                if (h[i] > 0) {
                    h[i]--;
                    edgeFlag = false;
                } else if (!edgeFlag) {
                    result++;
                    edgeFlag = true;
                }
            } {
                if (h[i] > 0) {
                    h[i]--;
                    edgeFlag = false;
                } else if (!edgeFlag) {
                    result++;
                    edgeFlag = true;
                }
            } if (h[i] > 0) {
                    h[i]--;
                    edgeFlag = false;
                } else if (!edgeFlag) {
                    result++;
                    edgeFlag = true;
                } h[i] > 0 h[i] h i 0 {
                    h[i]--;
                    edgeFlag = false;
                } h[i]-- h[i] h i edgeFlag = false edgeFlag false if (!edgeFlag) {
                    result++;
                    edgeFlag = true;
                } !edgeFlag edgeFlag {
                    result++;
                    edgeFlag = true;
                } result++ result edgeFlag = true edgeFlag true if (!edgeFlag) {
                result++;
            } !edgeFlag edgeFlag {
                result++;
            } result++ result System.out.println(result) System.out.println System.out System System.out result String args[] args public class Main {

    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        Integer[] h = new Integer[n];
        int maxHeight = 0;
        for (int i = 0; i < n; i++) {
            h[i] = Integer.parseInt(sc.next());
            maxHeight = Math.max(maxHeight, h[i]);
        }

        int result = 0;
        for (int j = 0; j < maxHeight; j++) {
            boolean edgeFlag = true;
            for (int i = 0; i < n; i++) {
                if (h[i] > 0) {
                    h[i]--;
                    edgeFlag = false;
                } else if (!edgeFlag) {
                    result++;
                    edgeFlag = true;
                }
            }
            if (!edgeFlag) {
                result++;
            }
        }

        System.out.println(result);
    }
} public class Main {

    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        Integer[] h = new Integer[n];
        int maxHeight = 0;
        for (int i = 0; i < n; i++) {
            h[i] = Integer.parseInt(sc.next());
            maxHeight = Math.max(maxHeight, h[i]);
        }

        int result = 0;
        for (int j = 0; j < maxHeight; j++) {
            boolean edgeFlag = true;
            for (int i = 0; i < n; i++) {
                if (h[i] > 0) {
                    h[i]--;
                    edgeFlag = false;
                } else if (!edgeFlag) {
                    result++;
                    edgeFlag = true;
                }
            }
            if (!edgeFlag) {
                result++;
            }
        }

        System.out.println(result);
    }
} Main
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        Integer[] h = new Integer[n];
        int maxHeight = 0;
        for (int i = 0; i < n; i++) {
            h[i] = Integer.parseInt(sc.next());
            maxHeight = Math.max(maxHeight, h[i]);
        }

        int result = 0;
        for (int j = 0; j < maxHeight; j++) {
            boolean edgeFlag = true;
            for (int i = 0; i < n; i++) {
                if (h[i] > 0) {
                    h[i]--;
                    edgeFlag = false;
                } else if (!edgeFlag) {
                    result++;
                    edgeFlag = true;
                }
            }
            if (!edgeFlag) {
                result++;
            }
        }

        System.out.println(result);
    }
}