import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] as = new int[n];
        for (int i = 0; i < n; i++) {
            as[i] = sc.nextInt();
        }

        int cnt = 0;
        while (true) {
            int nax = 0;
            for (int i = 0; i < n; i++) {
                nax = Math.max(nax, as[i]);
            }
            // System.err.println(nax);
            if (nax == 0) break;
            int stat = 0;
            for (int i = 0; i < n; i++) {
                if (stat <= 1 && as[i] == nax) {
                    as[i]--;
                    stat =  1;
                } else if (stat == 1 && as[i] != nax) {
                    break;
                }
            }
            cnt++;
        }
        System.out.println(cnt);
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] as = new int[n];
        for (int i = 0; i < n; i++) {
            as[i] = sc.nextInt();
        }

        int cnt = 0;
        while (true) {
            int nax = 0;
            for (int i = 0; i < n; i++) {
                nax = Math.max(nax, as[i]);
            }
            // System.err.println(nax);
            if (nax == 0) break;
            int stat = 0;
            for (int i = 0; i < n; i++) {
                if (stat <= 1 && as[i] == nax) {
                    as[i]--;
                    stat =  1;
                } else if (stat == 1 && as[i] != nax) {
                    break;
                }
            }
            cnt++;
        }
        System.out.println(cnt);
    }
} Main public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] as = new int[n];
        for (int i = 0; i < n; i++) {
            as[i] = sc.nextInt();
        }

        int cnt = 0;
        while (true) {
            int nax = 0;
            for (int i = 0; i < n; i++) {
                nax = Math.max(nax, as[i]);
            }
            // System.err.println(nax);
            if (nax == 0) break;
            int stat = 0;
            for (int i = 0; i < n; i++) {
                if (stat <= 1 && as[i] == nax) {
                    as[i]--;
                    stat =  1;
                } else if (stat == 1 && as[i] != nax) {
                    break;
                }
            }
            cnt++;
        }
        System.out.println(cnt);
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] as = new int[n];
        for (int i = 0; i < n; i++) {
            as[i] = sc.nextInt();
        }

        int cnt = 0;
        while (true) {
            int nax = 0;
            for (int i = 0; i < n; i++) {
                nax = Math.max(nax, as[i]);
            }
            // System.err.println(nax);
            if (nax == 0) break;
            int stat = 0;
            for (int i = 0; i < n; i++) {
                if (stat <= 1 && as[i] == nax) {
                    as[i]--;
                    stat =  1;
                } else if (stat == 1 && as[i] != nax) {
                    break;
                }
            }
            cnt++;
        }
        System.out.println(cnt);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] as = new int[n]; as new int[n] n for (int i = 0; i < n; i++) {
            as[i] = sc.nextInt();
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            as[i] = sc.nextInt();
        } {
            as[i] = sc.nextInt();
        } as[i] = sc.nextInt() as[i] as i sc.nextInt() sc.nextInt sc int cnt = 0; cnt 0 while (true) {
            int nax = 0;
            for (int i = 0; i < n; i++) {
                nax = Math.max(nax, as[i]);
            }
            // System.err.println(nax);
            if (nax == 0) break;
            int stat = 0;
            for (int i = 0; i < n; i++) {
                if (stat <= 1 && as[i] == nax) {
                    as[i]--;
                    stat =  1;
                } else if (stat == 1 && as[i] != nax) {
                    break;
                }
            }
            cnt++;
        } true {
            int nax = 0;
            for (int i = 0; i < n; i++) {
                nax = Math.max(nax, as[i]);
            }
            // System.err.println(nax);
            if (nax == 0) break;
            int stat = 0;
            for (int i = 0; i < n; i++) {
                if (stat <= 1 && as[i] == nax) {
                    as[i]--;
                    stat =  1;
                } else if (stat == 1 && as[i] != nax) {
                    break;
                }
            }
            cnt++;
        } int nax = 0; nax 0 for (int i = 0; i < n; i++) {
                nax = Math.max(nax, as[i]);
            } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
                nax = Math.max(nax, as[i]);
            } {
                nax = Math.max(nax, as[i]);
            } nax = Math.max(nax, as[i]) nax Math.max(nax, as[i]) Math.max Math nax as[i] as i if (nax == 0) break; nax == 0 nax 0 break; int stat = 0; stat 0 for (int i = 0; i < n; i++) {
                if (stat <= 1 && as[i] == nax) {
                    as[i]--;
                    stat =  1;
                } else if (stat == 1 && as[i] != nax) {
                    break;
                }
            } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
                if (stat <= 1 && as[i] == nax) {
                    as[i]--;
                    stat =  1;
                } else if (stat == 1 && as[i] != nax) {
                    break;
                }
            } {
                if (stat <= 1 && as[i] == nax) {
                    as[i]--;
                    stat =  1;
                } else if (stat == 1 && as[i] != nax) {
                    break;
                }
            } if (stat <= 1 && as[i] == nax) {
                    as[i]--;
                    stat =  1;
                } else if (stat == 1 && as[i] != nax) {
                    break;
                } stat <= 1 && as[i] == nax stat <= 1 stat 1 as[i] == nax as[i] as i nax {
                    as[i]--;
                    stat =  1;
                } as[i]-- as[i] as i stat =  1 stat 1 if (stat == 1 && as[i] != nax) {
                    break;
                } stat == 1 && as[i] != nax stat == 1 stat 1 as[i] != nax as[i] as i nax {
                    break;
                } break; cnt++ cnt System.out.println(cnt) System.out.println System.out System System.out cnt String args[] args public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] as = new int[n];
        for (int i = 0; i < n; i++) {
            as[i] = sc.nextInt();
        }

        int cnt = 0;
        while (true) {
            int nax = 0;
            for (int i = 0; i < n; i++) {
                nax = Math.max(nax, as[i]);
            }
            // System.err.println(nax);
            if (nax == 0) break;
            int stat = 0;
            for (int i = 0; i < n; i++) {
                if (stat <= 1 && as[i] == nax) {
                    as[i]--;
                    stat =  1;
                } else if (stat == 1 && as[i] != nax) {
                    break;
                }
            }
            cnt++;
        }
        System.out.println(cnt);
    }
} public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] as = new int[n];
        for (int i = 0; i < n; i++) {
            as[i] = sc.nextInt();
        }

        int cnt = 0;
        while (true) {
            int nax = 0;
            for (int i = 0; i < n; i++) {
                nax = Math.max(nax, as[i]);
            }
            // System.err.println(nax);
            if (nax == 0) break;
            int stat = 0;
            for (int i = 0; i < n; i++) {
                if (stat <= 1 && as[i] == nax) {
                    as[i]--;
                    stat =  1;
                } else if (stat == 1 && as[i] != nax) {
                    break;
                }
            }
            cnt++;
        }
        System.out.println(cnt);
    }
} Main
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] as = new int[n];
        for (int i = 0; i < n; i++) {
            as[i] = sc.nextInt();
        }

        int cnt = 0;
        while (true) {
            int nax = 0;
            for (int i = 0; i < n; i++) {
                nax = Math.max(nax, as[i]);
            }
            // System.err.println(nax);
            if (nax == 0) break;
            int stat = 0;
            for (int i = 0; i < n; i++) {
                if (stat <= 1 && as[i] == nax) {
                    as[i]--;
                    stat =  1;
                } else if (stat == 1 && as[i] != nax) {
                    break;
                }
            }
            cnt++;
        }
        System.out.println(cnt);
    }
}