#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
long long int power(long long int x, long long int n) {
  long long int result = 1;
  while (n > 0) {
    if (n % 2 == 1) result = result * x;
    x = x * x;
    n = n / 2;
  }
  return result;
}
void solve() {
  long long int n, x1, y1, x2, y2;
  cin >> n >> x1 >> y1 >> x2 >> y2;
  long long int min1 = 0, min2 = 0;
  long long int x12 = x2, y12 = y2;
  long long int cnt1 = 0, cnt2 = 0;
  while (x1 != x12 || y1 != y12) {
    if (x12 < n && y12 == n) {
      x12++;
    } else if (x12 == n && y12 > 0) {
      y12--;
    } else if (y12 == 0 && x12 > 0) {
      x12--;
    } else if (x12 == 0 && y12 < n) {
      y12++;
    }
    cnt1++;
  }
  x12 = x2, y12 = y2;
  while (x1 != x12 || y1 != y12) {
    if (x12 == 0 && y12 > 0) {
      y12--;
    } else if (x12 < n && y12 == 0) {
      x12++;
    } else if (y12 < n && x12 == n) {
      y12++;
    } else if (x12 > 0 && y12 == n) {
      x12--;
    }
    cnt2++;
  }
  cout << min(cnt1, cnt2) << "\n";
}
signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  long long int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
