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