#include <bits/stdc++.h>
using namespace std;
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
bool ISINT(double x) { return fabs(x - (int)x) < EPS; }
bool ISEQ(double x, double y) { return fabs(x - y) < EPS; }
string itos(long long n) {
  stringstream ss;
  ss << n;
  return ss.str();
}
int main(void) {
  int n, x1, y1, x2, y2;
  cin >> n >> x1 >> y1 >> x2 >> y2;
  int dist1 = x1;
  if (x1 == n) {
    dist1 += y1;
  } else if (x1 == 0 && y1 != 0) {
    dist1 = n * 3 + (n - y1);
  } else if (0 < x1 && x1 <= n && y1 != 0) {
    dist1 = n * 2 + (n - x1);
  }
  int dist2 = x2;
  if (x2 == n) {
    dist2 += y2;
  } else if (x2 == 0 && y2 != 0) {
    dist2 = n * 3 + (n - y2);
  } else if (0 < x2 && x2 <= n && y2 != 0) {
    dist2 = n * 2 + (n - x2);
  }
  cout << min(abs(dist1 - dist2), abs(n * 4 - abs(dist1 - dist2))) << endl;
  return 0;
}
