import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;

void main()
{
  auto kt = readln.chomp.split.map!(to!int);
  auto a = readln.chomp.split.map!(to!int).array;
  int res;
  int prev = -1;
  foreach_reverse (n; 1..kt[0]+1) {
    int index = -1;
    int max_n;
    foreach (i, e; a) {
      if (e == n) {
        index = i.to!int;
        break;
      }
      if (i == prev) {
        continue;
      }
      if (e > max_n) {
        index = i.to!int;
        max_n = e;
      }
    }
    a[index]--;
    if (prev == index) res++;
    prev = index;
  }
  res.writeln;
}
