#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x1, y1, x2, y2, dist;
  cin >> n >> x1 >> y1 >> x2 >> y2;
  int len1 = x1 + y1, len2 = x2 + y2;
  if ((x1 - y1) * (x2 - y2) >= 0)
    dist = abs(x1 + y1 - x2 - y2);
  else
    dist = x1 + y1 + x2 + y2;
  cout << min(dist, 4 * n - dist) << endl;
}
