#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  long long n, a, b, c, d;
  cin >> n >> a >> b >> c >> d;
  long long f = c - b, g = d - a;
  long long ans = 0;
  for (long long x1 = 1; x1 <= n; x1++) {
    long long x2 = x1 - f;
    long long x5 = x2 - g;
    long long x4 = x5 + f;
    long long xx1 = x4 + g;
    if (xx1 == x1 && min({x2, x4, x5}) >= 1 && max({x2, x4, x5}) <= n) ans += n;
  }
  cout << ans << '\n';
}
