#include <bits/stdc++.h>
using namespace std;
void init() {}
int l(int n, int x, int y) {
  if (y == 0) return x;
  if (x == n) return n + y;
  if (y == n) return 2 * n + (n - x);
  return 3 * n + (n - y);
}
void solve() {
  int n, x1, y1, x2, y2;
  cin >> n >> x1 >> y1 >> x2 >> y2;
  int l1 = l(n, x1, y1);
  int l2 = l(n, x2, y2);
  if (l1 > l2) swap(l1, l2);
  cout << min(l2 - l1, l1 + (4 * n - l2)) << endl;
}
int main() {
  init();
  solve();
  return 0;
}
