#include <bits/stdc++.h>
using namespace std;
void input() {}
int n;
int find(int x, int y) {
  if (x == 0)
    return 4;
  else if (y == n)
    return 3;
  else if (x == n)
    return 2;
  else if (y == 0)
    return 1;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  input();
  int x1, y1, x2, y2;
  cin >> n >> x1 >> y1 >> x2 >> y2;
  long long int p1, p2;
  if (find(x1, y1) == 1 || find(x1, y1) == 2) {
    p1 = x1 + y1;
  } else
    p1 = 4 * n - (x1 + y1);
  if (find(x2, y2) == 1 || find(x2, y2) == 2) {
    p2 = x2 + y2;
  } else
    p2 = 4 * n - (x2 + y2);
  cout << min(abs(p1 - p2), 4 * n - abs(p1 - p2));
}
