#include <bits/stdc++.h>
using namespace std;
const int N = 1100;
const int inf = 1 << 30;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int n, x1, y1_, x2, y2;
int d[N][N];
queue<pair<int, int> > q;
bool check(int x, int y) {
  if (x < 0 || y < 0 || x > n || y > n) return false;
  if (x == 0 || x == n || y == 0 || y == n)
    return true;
  else
    return false;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> x1 >> y1_ >> x2 >> y2;
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= n; j++) d[i][j] = inf;
  }
  d[x1][y1_] = 0;
  q.push(make_pair(x1, y1_));
  while (q.empty() == false) {
    int x = q.front().first;
    int y = q.front().second;
    q.pop();
    for (int i = 0; i < 4; i++) {
      int vx = x + dx[i];
      int vy = y + dy[i];
      if (check(vx, vy) && d[x][y] + 1 < d[vx][vy]) {
        d[vx][vy] = d[x][y] + 1;
        q.push(make_pair(vx, vy));
      }
    }
  }
  cout << d[x2][y2];
  return 0;
}
