#include <bits/stdc++.h>
using namespace std;
int main() {
  long long i, n, a, b, c, d, min, max;
  cin >> n >> a >> b >> c >> d;
  min = n;
  max = 1;
  if (c - b > 0) max = 1 + c - b;
  if (1 + d - a > max) max = 1 + d - a;
  if (1 + d + c - a - b > max) max = 1 + d + c - a - b;
  if (c - b < 0) min = n + c - b;
  if (n + d - a < min) min = n + d - a;
  if (n + d + c - a - b < min) min = n + d + c - a - b;
  i = min - max + 1;
  if (i < 0) i = 0;
  i *= n;
  cout << i << endl;
  return 0;
}
