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