import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in Actual solution is at the top
 *
 * @author Silviase
 */
public class Main {

  public static void main(String[] args) {
    InputStream inputStream = System.in;
    OutputStream outputStream = System.out;
    Scanner in = new Scanner(inputStream);
    PrintWriter out = new PrintWriter(outputStream);
    CGrandGarden solver = new CGrandGarden();
    solver.solve(1, in, out);
    out.close();
  }

  static class CGrandGarden {

    public void solve(int testNumber, Scanner in, PrintWriter out) {
      int n = in.nextInt();
      ArrayList<Integer> a = new ArrayList<>();
      for (int i = 0; i < n; i++) {
        a.add(in.nextInt());
      }

      out.println(func(a));

    }

    int func(ArrayList<Integer> a) {
      // a.forEach(x -> System.out.print(x + " "));

      if (a.size() == 0) {
        return 0;
      }

      int res = 0;

      while (!a.contains(0)) {
        res++;
        for (int i = 0; i < a.size(); i++) {
          a.set(i, a.get(i) - 1);
        }
      }

      ArrayList<Integer> b = new ArrayList<>();
      for (int i = 0; i < a.size(); i++) {
        if (a.get(i) != 0) {
          b.add(a.get(i));
        } else {
          res += func(b);
          b.clear();
        }
      }
      res += func(b);
      return res;
    }

  }
}
 import java.io.OutputStream; OutputStream java.io import java.io.IOException; IOException java.io import java.io.InputStream; InputStream java.io import java.io.PrintWriter; PrintWriter java.io import java.util.Scanner; Scanner java.util import java.util.ArrayList; ArrayList java.util public class Main {

  public static void main(String[] args) {
    InputStream inputStream = System.in;
    OutputStream outputStream = System.out;
    Scanner in = new Scanner(inputStream);
    PrintWriter out = new PrintWriter(outputStream);
    CGrandGarden solver = new CGrandGarden();
    solver.solve(1, in, out);
    out.close();
  }

  static class CGrandGarden {

    public void solve(int testNumber, Scanner in, PrintWriter out) {
      int n = in.nextInt();
      ArrayList<Integer> a = new ArrayList<>();
      for (int i = 0; i < n; i++) {
        a.add(in.nextInt());
      }

      out.println(func(a));

    }

    int func(ArrayList<Integer> a) {
      // a.forEach(x -> System.out.print(x + " "));

      if (a.size() == 0) {
        return 0;
      }

      int res = 0;

      while (!a.contains(0)) {
        res++;
        for (int i = 0; i < a.size(); i++) {
          a.set(i, a.get(i) - 1);
        }
      }

      ArrayList<Integer> b = new ArrayList<>();
      for (int i = 0; i < a.size(); i++) {
        if (a.get(i) != 0) {
          b.add(a.get(i));
        } else {
          res += func(b);
          b.clear();
        }
      }
      res += func(b);
      return res;
    }

  }
} Main public static void main(String[] args) {
    InputStream inputStream = System.in;
    OutputStream outputStream = System.out;
    Scanner in = new Scanner(inputStream);
    PrintWriter out = new PrintWriter(outputStream);
    CGrandGarden solver = new CGrandGarden();
    solver.solve(1, in, out);
    out.close();
  } main {
    InputStream inputStream = System.in;
    OutputStream outputStream = System.out;
    Scanner in = new Scanner(inputStream);
    PrintWriter out = new PrintWriter(outputStream);
    CGrandGarden solver = new CGrandGarden();
    solver.solve(1, in, out);
    out.close();
  } InputStream inputStream = System.in; inputStream System.in System System.in OutputStream outputStream = System.out; outputStream System.out System System.out Scanner in = new Scanner(inputStream); in new Scanner(inputStream) PrintWriter out = new PrintWriter(outputStream); out new PrintWriter(outputStream) CGrandGarden solver = new CGrandGarden(); solver new CGrandGarden() solver.solve(1, in, out) solver.solve solver 1 in out out.close() out.close out String[] args args static class CGrandGarden {

    public void solve(int testNumber, Scanner in, PrintWriter out) {
      int n = in.nextInt();
      ArrayList<Integer> a = new ArrayList<>();
      for (int i = 0; i < n; i++) {
        a.add(in.nextInt());
      }

      out.println(func(a));

    }

    int func(ArrayList<Integer> a) {
      // a.forEach(x -> System.out.print(x + " "));

      if (a.size() == 0) {
        return 0;
      }

      int res = 0;

      while (!a.contains(0)) {
        res++;
        for (int i = 0; i < a.size(); i++) {
          a.set(i, a.get(i) - 1);
        }
      }

      ArrayList<Integer> b = new ArrayList<>();
      for (int i = 0; i < a.size(); i++) {
        if (a.get(i) != 0) {
          b.add(a.get(i));
        } else {
          res += func(b);
          b.clear();
        }
      }
      res += func(b);
      return res;
    }

  } CGrandGarden public void solve(int testNumber, Scanner in, PrintWriter out) {
      int n = in.nextInt();
      ArrayList<Integer> a = new ArrayList<>();
      for (int i = 0; i < n; i++) {
        a.add(in.nextInt());
      }

      out.println(func(a));

    } solve {
      int n = in.nextInt();
      ArrayList<Integer> a = new ArrayList<>();
      for (int i = 0; i < n; i++) {
        a.add(in.nextInt());
      }

      out.println(func(a));

    } int n = in.nextInt(); n in.nextInt() in.nextInt in ArrayList<Integer> a = new ArrayList<>(); a new ArrayList<>() for (int i = 0; i < n; i++) {
        a.add(in.nextInt());
      } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
        a.add(in.nextInt());
      } {
        a.add(in.nextInt());
      } a.add(in.nextInt()) a.add a in.nextInt() in.nextInt in out.println(func(a)) out.println out func(a) func a int testNumber testNumber Scanner in in PrintWriter out out int func(ArrayList<Integer> a) {
      // a.forEach(x -> System.out.print(x + " "));

      if (a.size() == 0) {
        return 0;
      }

      int res = 0;

      while (!a.contains(0)) {
        res++;
        for (int i = 0; i < a.size(); i++) {
          a.set(i, a.get(i) - 1);
        }
      }

      ArrayList<Integer> b = new ArrayList<>();
      for (int i = 0; i < a.size(); i++) {
        if (a.get(i) != 0) {
          b.add(a.get(i));
        } else {
          res += func(b);
          b.clear();
        }
      }
      res += func(b);
      return res;
    } func {
      // a.forEach(x -> System.out.print(x + " "));

      if (a.size() == 0) {
        return 0;
      }

      int res = 0;

      while (!a.contains(0)) {
        res++;
        for (int i = 0; i < a.size(); i++) {
          a.set(i, a.get(i) - 1);
        }
      }

      ArrayList<Integer> b = new ArrayList<>();
      for (int i = 0; i < a.size(); i++) {
        if (a.get(i) != 0) {
          b.add(a.get(i));
        } else {
          res += func(b);
          b.clear();
        }
      }
      res += func(b);
      return res;
    } if (a.size() == 0) {
        return 0;
      } a.size() == 0 a.size() a.size a 0 {
        return 0;
      } return 0; 0 int res = 0; res 0 while (!a.contains(0)) {
        res++;
        for (int i = 0; i < a.size(); i++) {
          a.set(i, a.get(i) - 1);
        }
      } !a.contains(0) a.contains(0) a.contains a 0 {
        res++;
        for (int i = 0; i < a.size(); i++) {
          a.set(i, a.get(i) - 1);
        }
      } res++ res for (int i = 0; i < a.size(); i++) {
          a.set(i, a.get(i) - 1);
        } int i = 0; int i = 0; i 0 i < a.size() i a.size() a.size a i++ i++ i {
          a.set(i, a.get(i) - 1);
        } {
          a.set(i, a.get(i) - 1);
        } a.set(i, a.get(i) - 1) a.set a i a.get(i) - 1 a.get(i) a.get a i 1 ArrayList<Integer> b = new ArrayList<>(); b new ArrayList<>() for (int i = 0; i < a.size(); i++) {
        if (a.get(i) != 0) {
          b.add(a.get(i));
        } else {
          res += func(b);
          b.clear();
        }
      } int i = 0; int i = 0; i 0 i < a.size() i a.size() a.size a i++ i++ i {
        if (a.get(i) != 0) {
          b.add(a.get(i));
        } else {
          res += func(b);
          b.clear();
        }
      } {
        if (a.get(i) != 0) {
          b.add(a.get(i));
        } else {
          res += func(b);
          b.clear();
        }
      } if (a.get(i) != 0) {
          b.add(a.get(i));
        } else {
          res += func(b);
          b.clear();
        } a.get(i) != 0 a.get(i) a.get a i 0 {
          b.add(a.get(i));
        } b.add(a.get(i)) b.add b a.get(i) a.get a i {
          res += func(b);
          b.clear();
        } res += func(b) res func(b) func b b.clear() b.clear b res += func(b) res func(b) func b return res; res ArrayList<Integer> a a public class Main {

  public static void main(String[] args) {
    InputStream inputStream = System.in;
    OutputStream outputStream = System.out;
    Scanner in = new Scanner(inputStream);
    PrintWriter out = new PrintWriter(outputStream);
    CGrandGarden solver = new CGrandGarden();
    solver.solve(1, in, out);
    out.close();
  }

  static class CGrandGarden {

    public void solve(int testNumber, Scanner in, PrintWriter out) {
      int n = in.nextInt();
      ArrayList<Integer> a = new ArrayList<>();
      for (int i = 0; i < n; i++) {
        a.add(in.nextInt());
      }

      out.println(func(a));

    }

    int func(ArrayList<Integer> a) {
      // a.forEach(x -> System.out.print(x + " "));

      if (a.size() == 0) {
        return 0;
      }

      int res = 0;

      while (!a.contains(0)) {
        res++;
        for (int i = 0; i < a.size(); i++) {
          a.set(i, a.get(i) - 1);
        }
      }

      ArrayList<Integer> b = new ArrayList<>();
      for (int i = 0; i < a.size(); i++) {
        if (a.get(i) != 0) {
          b.add(a.get(i));
        } else {
          res += func(b);
          b.clear();
        }
      }
      res += func(b);
      return res;
    }

  }
} public class Main {

  public static void main(String[] args) {
    InputStream inputStream = System.in;
    OutputStream outputStream = System.out;
    Scanner in = new Scanner(inputStream);
    PrintWriter out = new PrintWriter(outputStream);
    CGrandGarden solver = new CGrandGarden();
    solver.solve(1, in, out);
    out.close();
  }

  static class CGrandGarden {

    public void solve(int testNumber, Scanner in, PrintWriter out) {
      int n = in.nextInt();
      ArrayList<Integer> a = new ArrayList<>();
      for (int i = 0; i < n; i++) {
        a.add(in.nextInt());
      }

      out.println(func(a));

    }

    int func(ArrayList<Integer> a) {
      // a.forEach(x -> System.out.print(x + " "));

      if (a.size() == 0) {
        return 0;
      }

      int res = 0;

      while (!a.contains(0)) {
        res++;
        for (int i = 0; i < a.size(); i++) {
          a.set(i, a.get(i) - 1);
        }
      }

      ArrayList<Integer> b = new ArrayList<>();
      for (int i = 0; i < a.size(); i++) {
        if (a.get(i) != 0) {
          b.add(a.get(i));
        } else {
          res += func(b);
          b.clear();
        }
      }
      res += func(b);
      return res;
    }

  }
} Main
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in Actual solution is at the top
 *
 * @author Silviase
 */
public class Main {

  public static void main(String[] args) {
    InputStream inputStream = System.in;
    OutputStream outputStream = System.out;
    Scanner in = new Scanner(inputStream);
    PrintWriter out = new PrintWriter(outputStream);
    CGrandGarden solver = new CGrandGarden();
    solver.solve(1, in, out);
    out.close();
  }

  static class CGrandGarden {

    public void solve(int testNumber, Scanner in, PrintWriter out) {
      int n = in.nextInt();
      ArrayList<Integer> a = new ArrayList<>();
      for (int i = 0; i < n; i++) {
        a.add(in.nextInt());
      }

      out.println(func(a));

    }

    int func(ArrayList<Integer> a) {
      // a.forEach(x -> System.out.print(x + " "));

      if (a.size() == 0) {
        return 0;
      }

      int res = 0;

      while (!a.contains(0)) {
        res++;
        for (int i = 0; i < a.size(); i++) {
          a.set(i, a.get(i) - 1);
        }
      }

      ArrayList<Integer> b = new ArrayList<>();
      for (int i = 0; i < a.size(); i++) {
        if (a.get(i) != 0) {
          b.add(a.get(i));
        } else {
          res += func(b);
          b.clear();
        }
      }
      res += func(b);
      return res;
    }

  }
}

