#include <bits/stdc++.h>
using namespace std;
int x_1;
int y_1;
int x_2;
int y_2;
int n;
bool inBorder(int x, int y) {
  return (x == 0 || x == n || y == 0 || y == n) && x >= 0 && y >= 0 && x <= n &&
         y <= n;
}
int main() {
  cin >> n >> x_1 >> y_1 >> x_2 >> y_2;
  vector<vector<int> > al((n + 1) * (n + 1));
  for (int i = 0; i <= n; ++i) {
    for (int j = 0; j <= n; ++j) {
      if (!inBorder(i, j)) {
        continue;
      }
      for (int k = -1; k < 2; ++k) {
        for (int l = -1; l < 2; ++l) {
          if (abs(k) + abs(l) == 1 && inBorder(i + k, j + l)) {
            al[i * (n + 1) + j].push_back((i + k) * (n + 1) + j + l);
          }
        }
      }
    }
  }
  int source = x_1 * (n + 1) + y_1;
  int goal = x_2 * (n + 1) + y_2;
  queue<int> q;
  vector<int> dist((n + 1) * (n + 1), ((1 << 31) - 1));
  dist[source] = 0;
  q.push(source);
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    for (int i = 0; i < al[v].size(); ++i) {
      if (dist[al[v][i]] == ((1 << 31) - 1)) {
        dist[al[v][i]] = dist[v] + 1;
        q.push(al[v][i]);
      }
    }
  }
  cout << dist[goal] << endl;
  return 0;
};
