public void solve() throws IOException {
    while (true) {
      int n = nextInt();
      int t1 = nextInt();
      int t2 = nextInt();
      int t3 = nextInt();
      if (n == 0 && t1 == 0 && t2 == 0 && t3 == 0)
        break;

      int total = 4 * n - 1;
      if (t1 < t2)
        total += t2 - t1;
      else
        total += n + t2 - t1;
      if (t2 > t3)
        total += t2 - t3;
      else
        total += n + t2 - t3;
      System.out.println(total);
    }
  }