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