#include <bits/stdc++.h>
using namespace std;
int pointLen(int &x, int &y, int &n);
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, x1, y1, x2, y2;
  cin >> n >> x1 >> y1 >> x2 >> y2;
  int p1 = pointLen(x1, y1, n), p2 = pointLen(x2, y2, n);
  cout << min(abs(p1 - p2), 4 * n - abs(p1 - p2)) << '\n';
  return 0;
}
int pointLen(int &x, int &y, int &n) {
  int p;
  if (x == 0) {
    if (y == 0)
      p = 0;
    else
      p = 4 * n - y;
  } else {
    if (y == 0)
      p = x;
    else if (x == n)
      p = x + y;
    else
      p = 2 * n + (n - x);
  }
  return p;
}
