#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  ;
  int n, x1, y1, x2, y2;
  cin >> n >> x1 >> y1 >> x2 >> y2;
  int posx;
  int posy;
  if (y1 == n) {
    posx = 2 * (n) + n - x1;
  } else if (x1 == n) {
    posx = n + y1;
  } else if (y1 == 0) {
    posx = x1;
  } else if (x1 == 0) {
    posx = 3 * (n) + n - y1;
  }
  if (y2 == n) {
    posy = 2 * (n) + n - x2;
  } else if (x2 == n) {
    posy = n + y2;
  } else if (y2 == 0) {
    posy = x2;
  } else if (x2 == 0) {
    posy = 3 * (n) + n - y2;
  }
  cout << min(abs(posy - posx),
              (posx > posy ? 4 * n - posx + posy : 4 * n - posy + posx));
  return 0;
}
