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