#include <bits/stdc++.h>
using namespace std;
inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }
inline int two(int n) { return 1 << n; }
const long long mod = 1e9 + 7;
const int maxn = 1e5 + 5;
void pre() {}
void solve();
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int TC = 1;
  while (TC--) {
    solve();
  }
  return 0;
}
int abso(int a) { return a >= 0 ? a : -1 * a; }
void solve() {
  int n, x1, y1, x2, y2;
  cin >> n >> x1 >> y1 >> x2 >> y2;
  if (abso(x2 - x1) == n) {
    int dy = abso(y2 - y1);
    dy += 2 * (y1 <= y2 ? y1 : y2);
    if (dy > n) dy = 2 * n - dy;
    cout << n + dy;
    return;
  }
  if (abso(y2 - y1) == n) {
    int dx = abso(x2 - x1);
    dx += 2 * (x1 <= x2 ? x1 : x2);
    if (dx > n) dx = 2 * n - dx;
    cout << n + dx;
    return;
  }
  cout << abso(x2 - x1) + abso(y2 - y1);
  return;
}
