#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 5;
long long int g[maxn][maxn], visited[maxn][maxn], dis[maxn][maxn];
void cross(long long int n) {
  for (long long int i = 0; i < n + 1; i++) g[0][i] = 1;
  for (long long int i = 0; i < n + 1; i++) g[i][0] = 1;
  for (long long int i = 0; i < n + 1; i++) g[n][i] = 1;
  for (long long int i = 0; i < n + 1; i++) g[i][n] = 1;
}
long long int dx[4] = {1, -1, 0, 0};
long long int dy[4] = {0, 0, 1, -1};
bool inn(long long int a, long long int b, long long int n) {
  if (a >= 0 && a <= n && b >= 0 && b <= n) return true;
  return false;
}
void bfs(long long int x, long long int y, long long int n) {
  queue<pair<long long int, long long int> > q;
  q.push(make_pair(x, y));
  visited[x][y] = 1;
  dis[x][y] = 0;
  while (!q.empty()) {
    long long int u = q.front().first;
    long long int v = q.front().second;
    q.pop();
    for (long long int i = 0; i < 4; i++) {
      long long int a = u + dx[i];
      long long int b = v + dy[i];
      if (inn(a, b, n) && !visited[a][b] && g[a][b]) {
        q.push(make_pair(a, b));
        visited[a][b] = 1;
        dis[a][b] = dis[u][v] + 1;
      }
    }
  }
}
int main() {
  long long int n, x1, y1, x2, y2;
  cin >> n >> x1 >> y1 >> x2 >> y2;
  cross(n);
  bfs(x1, y1, n);
  cout << dis[x2][y2] << endl;
}
