#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
const int N = 1e6 + 7;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, x1, y1, x2, y2;
  cin >> n >> x1 >> y1 >> x2 >> y2;
  long long tot = 0;
  if (abs(y1 - y2) == n) {
    tot += abs(y1 - y2);
    tot += min(abs(x1 - 0) + abs(x2 - 0), abs(x1 - n) + abs(x2 - n));
  } else if (abs(x1 - x2) == n) {
    tot += abs(x1 - x2);
    tot += min(abs(y1 - 0) + abs(y2 - 0), abs(y1 - n) + abs(y2 - n));
  } else {
    tot += abs(x1 - x2);
    tot += abs(y1 - y2);
  }
  cout << tot << "\n";
}
