#include <bits/stdc++.h>
using namespace std;
int n, p, q, a, b;
bool visited[10001][10001];
int d[1001][1001];
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
queue<int> qx, qy;
inline double sqr(double z) { return z * z; }
bool in(double x1, double y1, double x2, double y2, double x3, double y3) {
  return (abs(sqrt(sqr(x1 - x3) + sqr(y1 - y3)) +
              sqrt(sqr(x2 - x3) + sqr(y2 - y3)) -
              sqrt(sqr(x2 - x1) + sqr(y2 - y1))) <= 0.000000001);
}
int main() {
  cin >> n >> a >> b >> p >> q;
  visited[a][b] = 1;
  qx.push(a);
  qy.push(b);
  double nn = n;
  while (!qx.empty() && !qy.empty()) {
    int x = qx.front();
    int y = qy.front();
    qx.pop();
    qy.pop();
    for (int j = 0; j < 4; j++) {
      int u = x + dx[j];
      int v = y + dy[j];
      double du = u;
      double dv = v;
      bool in1 = in(0, 0, 0, nn, du, dv);
      bool in2 = in(0, nn, nn, nn, du, dv);
      bool in3 = in(n, 0, nn, nn, du, dv);
      bool in4 = in(0, 0, nn, 0, du, dv);
      bool edge = in1 || in2 || in3 || in4;
      if (visited[u][v] == 0 && edge) {
        visited[u][v] = 1;
        qx.push(u);
        qy.push(v);
        d[u][v] = d[x][y] + 1;
      }
    }
  }
  cout << d[p][q] << endl;
}
