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());
        int[] h = new int[n];
        int min = 100;
        for (int i = 0; i < n; i++) {
            int temp = Integer.parseInt(sc.next());
            h[i] = temp;
            min = Math.min(min, temp);
        }
        int ans = min;
        for (int i = 0; i < n; i++) {
            h[i] -= min;
        }
        boolean allZ = false;
        while (!allZ) {
            int start = 0;
            int end = 0;
            boolean isNum = false;
            while (start < n) {
                min = 101;
                boolean isNum2 = false;
                for (int i = start; i < n; i++) {
                    end = i;
                    if (h[i] > 0) {
                        isNum = true;
                        isNum2 = true;
                    }
                    if (h[i] == 0 && isNum2) {
                        break;
                    }
                    end = i + 1;
                }
                if (!isNum) {
                    allZ = true;
                    break;
                }
                for (int i = start; i < end; i++) {
                    if (h[i] == 0) {
                        continue;
                    }
                    min = Math.min(min, h[i]);
                }
                if (min != 101) {
                    ans += min;
                }
                for (int i = start; i < end; i++) {
                    if (h[i] == 0) {
                        continue;
                    }
                    h[i] -= min;
                }
                start = end + 1;
            }
        }
        System.out.println(ans);
    }
} 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());
        int[] h = new int[n];
        int min = 100;
        for (int i = 0; i < n; i++) {
            int temp = Integer.parseInt(sc.next());
            h[i] = temp;
            min = Math.min(min, temp);
        }
        int ans = min;
        for (int i = 0; i < n; i++) {
            h[i] -= min;
        }
        boolean allZ = false;
        while (!allZ) {
            int start = 0;
            int end = 0;
            boolean isNum = false;
            while (start < n) {
                min = 101;
                boolean isNum2 = false;
                for (int i = start; i < n; i++) {
                    end = i;
                    if (h[i] > 0) {
                        isNum = true;
                        isNum2 = true;
                    }
                    if (h[i] == 0 && isNum2) {
                        break;
                    }
                    end = i + 1;
                }
                if (!isNum) {
                    allZ = true;
                    break;
                }
                for (int i = start; i < end; i++) {
                    if (h[i] == 0) {
                        continue;
                    }
                    min = Math.min(min, h[i]);
                }
                if (min != 101) {
                    ans += min;
                }
                for (int i = start; i < end; i++) {
                    if (h[i] == 0) {
                        continue;
                    }
                    h[i] -= min;
                }
                start = end + 1;
            }
        }
        System.out.println(ans);
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] h = new int[n];
        int min = 100;
        for (int i = 0; i < n; i++) {
            int temp = Integer.parseInt(sc.next());
            h[i] = temp;
            min = Math.min(min, temp);
        }
        int ans = min;
        for (int i = 0; i < n; i++) {
            h[i] -= min;
        }
        boolean allZ = false;
        while (!allZ) {
            int start = 0;
            int end = 0;
            boolean isNum = false;
            while (start < n) {
                min = 101;
                boolean isNum2 = false;
                for (int i = start; i < n; i++) {
                    end = i;
                    if (h[i] > 0) {
                        isNum = true;
                        isNum2 = true;
                    }
                    if (h[i] == 0 && isNum2) {
                        break;
                    }
                    end = i + 1;
                }
                if (!isNum) {
                    allZ = true;
                    break;
                }
                for (int i = start; i < end; i++) {
                    if (h[i] == 0) {
                        continue;
                    }
                    min = Math.min(min, h[i]);
                }
                if (min != 101) {
                    ans += min;
                }
                for (int i = start; i < end; i++) {
                    if (h[i] == 0) {
                        continue;
                    }
                    h[i] -= min;
                }
                start = end + 1;
            }
        }
        System.out.println(ans);
    } main {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] h = new int[n];
        int min = 100;
        for (int i = 0; i < n; i++) {
            int temp = Integer.parseInt(sc.next());
            h[i] = temp;
            min = Math.min(min, temp);
        }
        int ans = min;
        for (int i = 0; i < n; i++) {
            h[i] -= min;
        }
        boolean allZ = false;
        while (!allZ) {
            int start = 0;
            int end = 0;
            boolean isNum = false;
            while (start < n) {
                min = 101;
                boolean isNum2 = false;
                for (int i = start; i < n; i++) {
                    end = i;
                    if (h[i] > 0) {
                        isNum = true;
                        isNum2 = true;
                    }
                    if (h[i] == 0 && isNum2) {
                        break;
                    }
                    end = i + 1;
                }
                if (!isNum) {
                    allZ = true;
                    break;
                }
                for (int i = start; i < end; i++) {
                    if (h[i] == 0) {
                        continue;
                    }
                    min = Math.min(min, h[i]);
                }
                if (min != 101) {
                    ans += min;
                }
                for (int i = start; i < end; i++) {
                    if (h[i] == 0) {
                        continue;
                    }
                    h[i] -= min;
                }
                start = end + 1;
            }
        }
        System.out.println(ans);
    } 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 int[] h = new int[n]; h new int[n] n int min = 100; min 100 for (int i = 0; i < n; i++) {
            int temp = Integer.parseInt(sc.next());
            h[i] = temp;
            min = Math.min(min, temp);
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            int temp = Integer.parseInt(sc.next());
            h[i] = temp;
            min = Math.min(min, temp);
        } {
            int temp = Integer.parseInt(sc.next());
            h[i] = temp;
            min = Math.min(min, temp);
        } int temp = Integer.parseInt(sc.next()); temp Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc h[i] = temp h[i] h i temp min = Math.min(min, temp) min Math.min(min, temp) Math.min Math min temp int ans = min; ans min for (int i = 0; i < n; i++) {
            h[i] -= min;
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            h[i] -= min;
        } {
            h[i] -= min;
        } h[i] -= min h[i] h i min boolean allZ = false; allZ false while (!allZ) {
            int start = 0;
            int end = 0;
            boolean isNum = false;
            while (start < n) {
                min = 101;
                boolean isNum2 = false;
                for (int i = start; i < n; i++) {
                    end = i;
                    if (h[i] > 0) {
                        isNum = true;
                        isNum2 = true;
                    }
                    if (h[i] == 0 && isNum2) {
                        break;
                    }
                    end = i + 1;
                }
                if (!isNum) {
                    allZ = true;
                    break;
                }
                for (int i = start; i < end; i++) {
                    if (h[i] == 0) {
                        continue;
                    }
                    min = Math.min(min, h[i]);
                }
                if (min != 101) {
                    ans += min;
                }
                for (int i = start; i < end; i++) {
                    if (h[i] == 0) {
                        continue;
                    }
                    h[i] -= min;
                }
                start = end + 1;
            }
        } !allZ allZ {
            int start = 0;
            int end = 0;
            boolean isNum = false;
            while (start < n) {
                min = 101;
                boolean isNum2 = false;
                for (int i = start; i < n; i++) {
                    end = i;
                    if (h[i] > 0) {
                        isNum = true;
                        isNum2 = true;
                    }
                    if (h[i] == 0 && isNum2) {
                        break;
                    }
                    end = i + 1;
                }
                if (!isNum) {
                    allZ = true;
                    break;
                }
                for (int i = start; i < end; i++) {
                    if (h[i] == 0) {
                        continue;
                    }
                    min = Math.min(min, h[i]);
                }
                if (min != 101) {
                    ans += min;
                }
                for (int i = start; i < end; i++) {
                    if (h[i] == 0) {
                        continue;
                    }
                    h[i] -= min;
                }
                start = end + 1;
            }
        } int start = 0; start 0 int end = 0; end 0 boolean isNum = false; isNum false while (start < n) {
                min = 101;
                boolean isNum2 = false;
                for (int i = start; i < n; i++) {
                    end = i;
                    if (h[i] > 0) {
                        isNum = true;
                        isNum2 = true;
                    }
                    if (h[i] == 0 && isNum2) {
                        break;
                    }
                    end = i + 1;
                }
                if (!isNum) {
                    allZ = true;
                    break;
                }
                for (int i = start; i < end; i++) {
                    if (h[i] == 0) {
                        continue;
                    }
                    min = Math.min(min, h[i]);
                }
                if (min != 101) {
                    ans += min;
                }
                for (int i = start; i < end; i++) {
                    if (h[i] == 0) {
                        continue;
                    }
                    h[i] -= min;
                }
                start = end + 1;
            } start < n start n {
                min = 101;
                boolean isNum2 = false;
                for (int i = start; i < n; i++) {
                    end = i;
                    if (h[i] > 0) {
                        isNum = true;
                        isNum2 = true;
                    }
                    if (h[i] == 0 && isNum2) {
                        break;
                    }
                    end = i + 1;
                }
                if (!isNum) {
                    allZ = true;
                    break;
                }
                for (int i = start; i < end; i++) {
                    if (h[i] == 0) {
                        continue;
                    }
                    min = Math.min(min, h[i]);
                }
                if (min != 101) {
                    ans += min;
                }
                for (int i = start; i < end; i++) {
                    if (h[i] == 0) {
                        continue;
                    }
                    h[i] -= min;
                }
                start = end + 1;
            } min = 101 min 101 boolean isNum2 = false; isNum2 false for (int i = start; i < n; i++) {
                    end = i;
                    if (h[i] > 0) {
                        isNum = true;
                        isNum2 = true;
                    }
                    if (h[i] == 0 && isNum2) {
                        break;
                    }
                    end = i + 1;
                } int i = start; int i = start; i start i < n i n i++ i++ i {
                    end = i;
                    if (h[i] > 0) {
                        isNum = true;
                        isNum2 = true;
                    }
                    if (h[i] == 0 && isNum2) {
                        break;
                    }
                    end = i + 1;
                } {
                    end = i;
                    if (h[i] > 0) {
                        isNum = true;
                        isNum2 = true;
                    }
                    if (h[i] == 0 && isNum2) {
                        break;
                    }
                    end = i + 1;
                } end = i end i if (h[i] > 0) {
                        isNum = true;
                        isNum2 = true;
                    } h[i] > 0 h[i] h i 0 {
                        isNum = true;
                        isNum2 = true;
                    } isNum = true isNum true isNum2 = true isNum2 true if (h[i] == 0 && isNum2) {
                        break;
                    } h[i] == 0 && isNum2 h[i] == 0 h[i] h i 0 isNum2 {
                        break;
                    } break; end = i + 1 end i + 1 i 1 if (!isNum) {
                    allZ = true;
                    break;
                } !isNum isNum {
                    allZ = true;
                    break;
                } allZ = true allZ true break; for (int i = start; i < end; i++) {
                    if (h[i] == 0) {
                        continue;
                    }
                    min = Math.min(min, h[i]);
                } int i = start; int i = start; i start i < end i end i++ i++ i {
                    if (h[i] == 0) {
                        continue;
                    }
                    min = Math.min(min, h[i]);
                } {
                    if (h[i] == 0) {
                        continue;
                    }
                    min = Math.min(min, h[i]);
                } if (h[i] == 0) {
                        continue;
                    } h[i] == 0 h[i] h i 0 {
                        continue;
                    } continue; min = Math.min(min, h[i]) min Math.min(min, h[i]) Math.min Math min h[i] h i if (min != 101) {
                    ans += min;
                } min != 101 min 101 {
                    ans += min;
                } ans += min ans min for (int i = start; i < end; i++) {
                    if (h[i] == 0) {
                        continue;
                    }
                    h[i] -= min;
                } int i = start; int i = start; i start i < end i end i++ i++ i {
                    if (h[i] == 0) {
                        continue;
                    }
                    h[i] -= min;
                } {
                    if (h[i] == 0) {
                        continue;
                    }
                    h[i] -= min;
                } if (h[i] == 0) {
                        continue;
                    } h[i] == 0 h[i] h i 0 {
                        continue;
                    } continue; h[i] -= min h[i] h i min start = end + 1 start end + 1 end 1 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 sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] h = new int[n];
        int min = 100;
        for (int i = 0; i < n; i++) {
            int temp = Integer.parseInt(sc.next());
            h[i] = temp;
            min = Math.min(min, temp);
        }
        int ans = min;
        for (int i = 0; i < n; i++) {
            h[i] -= min;
        }
        boolean allZ = false;
        while (!allZ) {
            int start = 0;
            int end = 0;
            boolean isNum = false;
            while (start < n) {
                min = 101;
                boolean isNum2 = false;
                for (int i = start; i < n; i++) {
                    end = i;
                    if (h[i] > 0) {
                        isNum = true;
                        isNum2 = true;
                    }
                    if (h[i] == 0 && isNum2) {
                        break;
                    }
                    end = i + 1;
                }
                if (!isNum) {
                    allZ = true;
                    break;
                }
                for (int i = start; i < end; i++) {
                    if (h[i] == 0) {
                        continue;
                    }
                    min = Math.min(min, h[i]);
                }
                if (min != 101) {
                    ans += min;
                }
                for (int i = start; i < end; i++) {
                    if (h[i] == 0) {
                        continue;
                    }
                    h[i] -= min;
                }
                start = end + 1;
            }
        }
        System.out.println(ans);
    }
} public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] h = new int[n];
        int min = 100;
        for (int i = 0; i < n; i++) {
            int temp = Integer.parseInt(sc.next());
            h[i] = temp;
            min = Math.min(min, temp);
        }
        int ans = min;
        for (int i = 0; i < n; i++) {
            h[i] -= min;
        }
        boolean allZ = false;
        while (!allZ) {
            int start = 0;
            int end = 0;
            boolean isNum = false;
            while (start < n) {
                min = 101;
                boolean isNum2 = false;
                for (int i = start; i < n; i++) {
                    end = i;
                    if (h[i] > 0) {
                        isNum = true;
                        isNum2 = true;
                    }
                    if (h[i] == 0 && isNum2) {
                        break;
                    }
                    end = i + 1;
                }
                if (!isNum) {
                    allZ = true;
                    break;
                }
                for (int i = start; i < end; i++) {
                    if (h[i] == 0) {
                        continue;
                    }
                    min = Math.min(min, h[i]);
                }
                if (min != 101) {
                    ans += min;
                }
                for (int i = start; i < end; i++) {
                    if (h[i] == 0) {
                        continue;
                    }
                    h[i] -= min;
                }
                start = end + 1;
            }
        }
        System.out.println(ans);
    }
} 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());
        int[] h = new int[n];
        int min = 100;
        for (int i = 0; i < n; i++) {
            int temp = Integer.parseInt(sc.next());
            h[i] = temp;
            min = Math.min(min, temp);
        }
        int ans = min;
        for (int i = 0; i < n; i++) {
            h[i] -= min;
        }
        boolean allZ = false;
        while (!allZ) {
            int start = 0;
            int end = 0;
            boolean isNum = false;
            while (start < n) {
                min = 101;
                boolean isNum2 = false;
                for (int i = start; i < n; i++) {
                    end = i;
                    if (h[i] > 0) {
                        isNum = true;
                        isNum2 = true;
                    }
                    if (h[i] == 0 && isNum2) {
                        break;
                    }
                    end = i + 1;
                }
                if (!isNum) {
                    allZ = true;
                    break;
                }
                for (int i = start; i < end; i++) {
                    if (h[i] == 0) {
                        continue;
                    }
                    min = Math.min(min, h[i]);
                }
                if (min != 101) {
                    ans += min;
                }
                for (int i = start; i < end; i++) {
                    if (h[i] == 0) {
                        continue;
                    }
                    h[i] -= min;
                }
                start = end + 1;
            }
        }
        System.out.println(ans);
    }
}