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