import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] h = new int[n + 1];
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }
        h[n] = 0;
        
        int count = 0;
        for (int i = 0; i < n; i++) {
            if (h[i] == 0) continue;
            int min = h[i];
            
            for (int j = i + 1; j <= n; j++) {
                if (h[j] != 0) {
                    min = Math.min(min, h[j]);
                } else {
                    for (int k = i; k <= j - 1; k++) {
                        h[k] -= min;
                    }
                    count += min;
                    if (h[i] != 0) {
                        i--;
                    }
                    break;
                }
            }
        }
        
        System.out.println(count);
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] h = new int[n + 1];
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }
        h[n] = 0;
        
        int count = 0;
        for (int i = 0; i < n; i++) {
            if (h[i] == 0) continue;
            int min = h[i];
            
            for (int j = i + 1; j <= n; j++) {
                if (h[j] != 0) {
                    min = Math.min(min, h[j]);
                } else {
                    for (int k = i; k <= j - 1; k++) {
                        h[k] -= min;
                    }
                    count += min;
                    if (h[i] != 0) {
                        i--;
                    }
                    break;
                }
            }
        }
        
        System.out.println(count);
    }
} Main public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] h = new int[n + 1];
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }
        h[n] = 0;
        
        int count = 0;
        for (int i = 0; i < n; i++) {
            if (h[i] == 0) continue;
            int min = h[i];
            
            for (int j = i + 1; j <= n; j++) {
                if (h[j] != 0) {
                    min = Math.min(min, h[j]);
                } else {
                    for (int k = i; k <= j - 1; k++) {
                        h[k] -= min;
                    }
                    count += min;
                    if (h[i] != 0) {
                        i--;
                    }
                    break;
                }
            }
        }
        
        System.out.println(count);
    } main {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] h = new int[n + 1];
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }
        h[n] = 0;
        
        int count = 0;
        for (int i = 0; i < n; i++) {
            if (h[i] == 0) continue;
            int min = h[i];
            
            for (int j = i + 1; j <= n; j++) {
                if (h[j] != 0) {
                    min = Math.min(min, h[j]);
                } else {
                    for (int k = i; k <= j - 1; k++) {
                        h[k] -= min;
                    }
                    count += min;
                    if (h[i] != 0) {
                        i--;
                    }
                    break;
                }
            }
        }
        
        System.out.println(count);
    } 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 + 1]; h new int[n + 1] n + 1 n 1 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 h[n] = 0 h[n] h n 0 int count = 0; count 0 for (int i = 0; i < n; i++) {
            if (h[i] == 0) continue;
            int min = h[i];
            
            for (int j = i + 1; j <= n; j++) {
                if (h[j] != 0) {
                    min = Math.min(min, h[j]);
                } else {
                    for (int k = i; k <= j - 1; k++) {
                        h[k] -= min;
                    }
                    count += min;
                    if (h[i] != 0) {
                        i--;
                    }
                    break;
                }
            }
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            if (h[i] == 0) continue;
            int min = h[i];
            
            for (int j = i + 1; j <= n; j++) {
                if (h[j] != 0) {
                    min = Math.min(min, h[j]);
                } else {
                    for (int k = i; k <= j - 1; k++) {
                        h[k] -= min;
                    }
                    count += min;
                    if (h[i] != 0) {
                        i--;
                    }
                    break;
                }
            }
        } {
            if (h[i] == 0) continue;
            int min = h[i];
            
            for (int j = i + 1; j <= n; j++) {
                if (h[j] != 0) {
                    min = Math.min(min, h[j]);
                } else {
                    for (int k = i; k <= j - 1; k++) {
                        h[k] -= min;
                    }
                    count += min;
                    if (h[i] != 0) {
                        i--;
                    }
                    break;
                }
            }
        } if (h[i] == 0) continue; h[i] == 0 h[i] h i 0 continue; int min = h[i]; min h[i] h i for (int j = i + 1; j <= n; j++) {
                if (h[j] != 0) {
                    min = Math.min(min, h[j]);
                } else {
                    for (int k = i; k <= j - 1; k++) {
                        h[k] -= min;
                    }
                    count += min;
                    if (h[i] != 0) {
                        i--;
                    }
                    break;
                }
            } int j = i + 1; int j = i + 1; j i + 1 i 1 j <= n j n j++ j++ j {
                if (h[j] != 0) {
                    min = Math.min(min, h[j]);
                } else {
                    for (int k = i; k <= j - 1; k++) {
                        h[k] -= min;
                    }
                    count += min;
                    if (h[i] != 0) {
                        i--;
                    }
                    break;
                }
            } {
                if (h[j] != 0) {
                    min = Math.min(min, h[j]);
                } else {
                    for (int k = i; k <= j - 1; k++) {
                        h[k] -= min;
                    }
                    count += min;
                    if (h[i] != 0) {
                        i--;
                    }
                    break;
                }
            } if (h[j] != 0) {
                    min = Math.min(min, h[j]);
                } else {
                    for (int k = i; k <= j - 1; k++) {
                        h[k] -= min;
                    }
                    count += min;
                    if (h[i] != 0) {
                        i--;
                    }
                    break;
                } h[j] != 0 h[j] h j 0 {
                    min = Math.min(min, h[j]);
                } min = Math.min(min, h[j]) min Math.min(min, h[j]) Math.min Math min h[j] h j {
                    for (int k = i; k <= j - 1; k++) {
                        h[k] -= min;
                    }
                    count += min;
                    if (h[i] != 0) {
                        i--;
                    }
                    break;
                } for (int k = i; k <= j - 1; k++) {
                        h[k] -= min;
                    } int k = i; int k = i; k i k <= j - 1 k j - 1 j 1 k++ k++ k {
                        h[k] -= min;
                    } {
                        h[k] -= min;
                    } h[k] -= min h[k] h k min count += min count min if (h[i] != 0) {
                        i--;
                    } h[i] != 0 h[i] h i 0 {
                        i--;
                    } i-- i break; System.out.println(count) System.out.println System.out System System.out count String[] args args public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] h = new int[n + 1];
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }
        h[n] = 0;
        
        int count = 0;
        for (int i = 0; i < n; i++) {
            if (h[i] == 0) continue;
            int min = h[i];
            
            for (int j = i + 1; j <= n; j++) {
                if (h[j] != 0) {
                    min = Math.min(min, h[j]);
                } else {
                    for (int k = i; k <= j - 1; k++) {
                        h[k] -= min;
                    }
                    count += min;
                    if (h[i] != 0) {
                        i--;
                    }
                    break;
                }
            }
        }
        
        System.out.println(count);
    }
} public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] h = new int[n + 1];
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }
        h[n] = 0;
        
        int count = 0;
        for (int i = 0; i < n; i++) {
            if (h[i] == 0) continue;
            int min = h[i];
            
            for (int j = i + 1; j <= n; j++) {
                if (h[j] != 0) {
                    min = Math.min(min, h[j]);
                } else {
                    for (int k = i; k <= j - 1; k++) {
                        h[k] -= min;
                    }
                    count += min;
                    if (h[i] != 0) {
                        i--;
                    }
                    break;
                }
            }
        }
        
        System.out.println(count);
    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] h = new int[n + 1];
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }
        h[n] = 0;
        
        int count = 0;
        for (int i = 0; i < n; i++) {
            if (h[i] == 0) continue;
            int min = h[i];
            
            for (int j = i + 1; j <= n; j++) {
                if (h[j] != 0) {
                    min = Math.min(min, h[j]);
                } else {
                    for (int k = i; k <= j - 1; k++) {
                        h[k] -= min;
                    }
                    count += min;
                    if (h[i] != 0) {
                        i--;
                    }
                    break;
                }
            }
        }
        
        System.out.println(count);
    }
}
