#include <bits/stdc++.h>
using namespace std;
void __print(int x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T>
void __print(const T &x) {
  int f = 0;
  cerr << '{';
  for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
long long dx[] = {-1, 0, 0, 1};
long long dy[] = {0, -1, 1, 0};
const long double pi = 3.1415926535897932384626433832795;
const long long INF = 1e18;
const long long mod = 1000000007;
const long long maxn = 1e3 + 5;
template <typename T>
void printv(const vector<T> &v) {
  for (auto i : v) cout << i << ' ';
  cout << '\n';
}
template <typename T>
void printv(const vector<pair<T, T>> &v) {
  for (auto p : v) cout << "(" << p.first << "," << p.second << "),";
  cout << '\n';
}
long long n, sx, sy, ex, ey;
long long dis[maxn][maxn];
bool vis[maxn][maxn];
bool ok(long long i, long long j) {
  if (i < 0 || j < 0 || i > n || j > n)
    return 0;
  else if (!vis[i][j] && (i == 0 || j == 0 || i == n || j == n))
    return 1;
  return 0;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(nullptr);
  cin >> n >> sx >> sy >> ex >> ey;
  queue<pair<long long, long long>> q;
  q.push({sx, sy});
  dis[sx][sy] = 0;
  vis[sx][sy] = 1;
  while (q.size() > 0) {
    auto v = q.front();
    q.pop();
    long long x = v.first, y = v.second;
    for (long long i = 0; i < 4; i++) {
      if (ok(x + dx[i], y + dy[i])) {
        if (!vis[x + dx[i]][y + dy[i]]) {
          vis[x + dx[i]][y + dy[i]] = 1;
          dis[x + dx[i]][y + dy[i]] = dis[x][y] + 1;
          q.push({x + dx[i], y + dy[i]});
        }
      }
    }
  }
  cout << dis[ex][ey] << '\n';
  return 0;
}
