#include <bits/stdc++.h>
using namespace std;
long long i, j, k, l, m, n, s, a[1111111], b[111111], c, cc, d, e, f, t;
string p, q, r[11111], w;
map<string, string> x, y;
vector<long long> u[1111], uu;
int main() {
  cin >> n >> c >> d >> e >> f;
  for (i = 1; i <= n; i++) {
    m = i + d - e;
    if (m < 1 || m > n) continue;
    m = i + c - f;
    if (m < 1 || m > n) continue;
    m = i + d - e + c - f;
    if (m < 1 || m > n) continue;
    s += n;
  }
  cout << s;
}
