#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x1, x2, y1, y2;
  int dis = 0;
  cin >> n >> x1 >> y1 >> x2 >> y2;
  if (abs(x1 - x2) == n)
    dis = min(y1 + y2 + n, 3 * n - y1 - y2);
  else if (abs(y1 - y2) == n)
    dis = min(x1 + x2 + n, 3 * n - x1 - x2);
  else
    dis = abs(x1 - x2) + abs(y1 - y2);
  cout << dis;
  return 0;
}
