import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) {
        int h[] = getInput();
        int cnt = 0;
        while (true) {
            int idx = 0;
            while (idx < h.length && h[idx] == 0) idx++;
            if (idx == h.length) {
                break;
            }
            while (idx < h.length && h[idx] > 0) {
                h[idx]--;
                idx++;
            }
            cnt++;
        }
        System.out.println(cnt);
        return;
    }

    private static int[] getInput()
    {
        int[] ret = null;
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        try {
            int n = Integer.parseInt(br.readLine());
            ret = new int[n];
            String hString[] = br.readLine().split("\\s");
            for (int i = 0; i < n; i++) {
                ret[i] = Integer.parseInt(hString[i]);
            }
        } catch (IOException e) {
            System.err.println(e.getMessage());
        }
        return ret;
    }

} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {

    public static void main(String[] args) {
        int h[] = getInput();
        int cnt = 0;
        while (true) {
            int idx = 0;
            while (idx < h.length && h[idx] == 0) idx++;
            if (idx == h.length) {
                break;
            }
            while (idx < h.length && h[idx] > 0) {
                h[idx]--;
                idx++;
            }
            cnt++;
        }
        System.out.println(cnt);
        return;
    }

    private static int[] getInput()
    {
        int[] ret = null;
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        try {
            int n = Integer.parseInt(br.readLine());
            ret = new int[n];
            String hString[] = br.readLine().split("\\s");
            for (int i = 0; i < n; i++) {
                ret[i] = Integer.parseInt(hString[i]);
            }
        } catch (IOException e) {
            System.err.println(e.getMessage());
        }
        return ret;
    }

} Main public static void main(String[] args) {
        int h[] = getInput();
        int cnt = 0;
        while (true) {
            int idx = 0;
            while (idx < h.length && h[idx] == 0) idx++;
            if (idx == h.length) {
                break;
            }
            while (idx < h.length && h[idx] > 0) {
                h[idx]--;
                idx++;
            }
            cnt++;
        }
        System.out.println(cnt);
        return;
    } main {
        int h[] = getInput();
        int cnt = 0;
        while (true) {
            int idx = 0;
            while (idx < h.length && h[idx] == 0) idx++;
            if (idx == h.length) {
                break;
            }
            while (idx < h.length && h[idx] > 0) {
                h[idx]--;
                idx++;
            }
            cnt++;
        }
        System.out.println(cnt);
        return;
    } int h[] = getInput(); h getInput() getInput int cnt = 0; cnt 0 while (true) {
            int idx = 0;
            while (idx < h.length && h[idx] == 0) idx++;
            if (idx == h.length) {
                break;
            }
            while (idx < h.length && h[idx] > 0) {
                h[idx]--;
                idx++;
            }
            cnt++;
        } true {
            int idx = 0;
            while (idx < h.length && h[idx] == 0) idx++;
            if (idx == h.length) {
                break;
            }
            while (idx < h.length && h[idx] > 0) {
                h[idx]--;
                idx++;
            }
            cnt++;
        } int idx = 0; idx 0 while (idx < h.length && h[idx] == 0) idx++; idx < h.length && h[idx] == 0 idx < h.length idx h.length h h.length h[idx] == 0 h[idx] h idx 0 idx++ idx if (idx == h.length) {
                break;
            } idx == h.length idx h.length h h.length {
                break;
            } break; while (idx < h.length && h[idx] > 0) {
                h[idx]--;
                idx++;
            } idx < h.length && h[idx] > 0 idx < h.length idx h.length h h.length h[idx] > 0 h[idx] h idx 0 {
                h[idx]--;
                idx++;
            } h[idx]-- h[idx] h idx idx++ idx cnt++ cnt System.out.println(cnt) System.out.println System.out System System.out cnt return; String[] args args private static int[] getInput()
    {
        int[] ret = null;
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        try {
            int n = Integer.parseInt(br.readLine());
            ret = new int[n];
            String hString[] = br.readLine().split("\\s");
            for (int i = 0; i < n; i++) {
                ret[i] = Integer.parseInt(hString[i]);
            }
        } catch (IOException e) {
            System.err.println(e.getMessage());
        }
        return ret;
    } getInput {
        int[] ret = null;
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        try {
            int n = Integer.parseInt(br.readLine());
            ret = new int[n];
            String hString[] = br.readLine().split("\\s");
            for (int i = 0; i < n; i++) {
                ret[i] = Integer.parseInt(hString[i]);
            }
        } catch (IOException e) {
            System.err.println(e.getMessage());
        }
        return ret;
    } int[] ret = null; ret null BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) try {
            int n = Integer.parseInt(br.readLine());
            ret = new int[n];
            String hString[] = br.readLine().split("\\s");
            for (int i = 0; i < n; i++) {
                ret[i] = Integer.parseInt(hString[i]);
            }
        } catch (IOException e) {
            System.err.println(e.getMessage());
        } catch (IOException e) {
            System.err.println(e.getMessage());
        } IOException e {
            System.err.println(e.getMessage());
        } System.err.println(e.getMessage()) System.err.println System.err System System.err e.getMessage() e.getMessage e {
            int n = Integer.parseInt(br.readLine());
            ret = new int[n];
            String hString[] = br.readLine().split("\\s");
            for (int i = 0; i < n; i++) {
                ret[i] = Integer.parseInt(hString[i]);
            }
        } int n = Integer.parseInt(br.readLine()); n Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br ret = new int[n] ret new int[n] n String hString[] = br.readLine().split("\\s"); hString br.readLine().split("\\s") br.readLine().split br.readLine() br.readLine br "\\s" for (int i = 0; i < n; i++) {
                ret[i] = Integer.parseInt(hString[i]);
            } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
                ret[i] = Integer.parseInt(hString[i]);
            } {
                ret[i] = Integer.parseInt(hString[i]);
            } ret[i] = Integer.parseInt(hString[i]) ret[i] ret i Integer.parseInt(hString[i]) Integer.parseInt Integer hString[i] hString i return ret; ret public class Main {

    public static void main(String[] args) {
        int h[] = getInput();
        int cnt = 0;
        while (true) {
            int idx = 0;
            while (idx < h.length && h[idx] == 0) idx++;
            if (idx == h.length) {
                break;
            }
            while (idx < h.length && h[idx] > 0) {
                h[idx]--;
                idx++;
            }
            cnt++;
        }
        System.out.println(cnt);
        return;
    }

    private static int[] getInput()
    {
        int[] ret = null;
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        try {
            int n = Integer.parseInt(br.readLine());
            ret = new int[n];
            String hString[] = br.readLine().split("\\s");
            for (int i = 0; i < n; i++) {
                ret[i] = Integer.parseInt(hString[i]);
            }
        } catch (IOException e) {
            System.err.println(e.getMessage());
        }
        return ret;
    }

} public class Main {

    public static void main(String[] args) {
        int h[] = getInput();
        int cnt = 0;
        while (true) {
            int idx = 0;
            while (idx < h.length && h[idx] == 0) idx++;
            if (idx == h.length) {
                break;
            }
            while (idx < h.length && h[idx] > 0) {
                h[idx]--;
                idx++;
            }
            cnt++;
        }
        System.out.println(cnt);
        return;
    }

    private static int[] getInput()
    {
        int[] ret = null;
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        try {
            int n = Integer.parseInt(br.readLine());
            ret = new int[n];
            String hString[] = br.readLine().split("\\s");
            for (int i = 0; i < n; i++) {
                ret[i] = Integer.parseInt(hString[i]);
            }
        } catch (IOException e) {
            System.err.println(e.getMessage());
        }
        return ret;
    }

} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) {
        int h[] = getInput();
        int cnt = 0;
        while (true) {
            int idx = 0;
            while (idx < h.length && h[idx] == 0) idx++;
            if (idx == h.length) {
                break;
            }
            while (idx < h.length && h[idx] > 0) {
                h[idx]--;
                idx++;
            }
            cnt++;
        }
        System.out.println(cnt);
        return;
    }

    private static int[] getInput()
    {
        int[] ret = null;
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        try {
            int n = Integer.parseInt(br.readLine());
            ret = new int[n];
            String hString[] = br.readLine().split("\\s");
            for (int i = 0; i < n; i++) {
                ret[i] = Integer.parseInt(hString[i]);
            }
        } catch (IOException e) {
            System.err.println(e.getMessage());
        }
        return ret;
    }

}
