#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, x, y, xx, yy;
  cin >> n >> x >> y >> xx >> yy;
  int a, b;
  if (x == 0 && y == 0) {
    a = 0;
  } else if (x == n && y == n) {
    a = n * 2;
  } else if (x == 0 && y != 0) {
    a = (n * 4) - y;
  } else if (x == n && y != n) {
    a = n + y;
  } else if (y == n && x != n) {
    a = (n * 2) + (n - x);
  } else if (y == 0 && x != n) {
    a = x;
  }
  if (xx == 0 && yy == 0) {
    b = 0;
  } else if (xx == n && yy == n) {
    b = n * 2;
  }
  if (xx == 0 && yy != 0) {
    b = (n * 4) - yy;
  } else if (xx == n && yy != n) {
    b = n + yy;
  } else if (yy == n && xx != n) {
    b = (n * 2) + (n - xx);
  } else if (yy == 0 && xx != n) {
    b = xx;
  }
  cout << min((n * 4) - abs(abs(max(a, b)) - abs(min(a, b))),
              abs(max(a, b)) - abs(min(a, b)))
       << endl;
  return 0;
}
