public Contest145C() throws Exception {
    BufferedReader in = new BufferedReader(new FileReader("input.txt"));
    FileWriter f = new FileWriter("output.txt");

    int days = Integer.valueOf(in.readLine());

    String[] temp = in.readLine().split(" ");

    ArrayList<Integer> temps = new ArrayList<Integer>();

    for (int x = 0; x < days; x++)
      temps.add(Integer.valueOf(temp[x]));

    boolean a = false;
    boolean b = false;
    if (temps.get(0) == 0)
      a = true;
    if (temps.get(temps.size() - 1) == 0)
      b = true;

    f.write(changeMe(temps, 0, a, b) + "\n");
    f.flush();
    f.close();
    in.close();
  }