#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int arr[n + 5][n + 5];
  int x1, y1, x2, y2, sum1 = 0, sum2 = 0, sum3 = 0, sum4 = 0, s_min = 0,
                      f_min = 0, t_min = 0;
  cin >> x1 >> y1 >> x2 >> y2;
  if (x1 == 0 && x2 == n || x2 == 0 && x1 == n) {
    cout << n + min(y1 + y2, n - y1 + n - y2) << endl;
  } else if (y1 == 0 && y2 == n || y2 == 0 && y1 == n) {
    cout << n + min(x1 + x2, n - x1 + n - x2) << endl;
  } else
    cout << abs(x1 - x2) + abs(y1 - y2) << endl;
  return 0;
}
