#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x1, y1, x2, y2;
  cin >> n >> x1 >> y1 >> x2 >> y2;
  int x, y, l = 1000000, ll;
  x = x1;
  y = y1;
  ll = 0;
  while (x != x2 || y != y2) {
    ll++;
    if (x == 0) {
      if (y > 0)
        y--;
      else
        x++;
    } else if (y == 0) {
      if (x < n)
        x++;
      else
        y++;
    } else if (x == n) {
      if (y < n)
        y++;
      else
        x--;
    } else if (y == n) {
      if (x > 0)
        x--;
      else
        y--;
    }
  }
  l = min(l, ll);
  x = x1;
  y = y1;
  ll = 0;
  while (x != x2 || y != y2) {
    ll++;
    if (x == 0) {
      if (y < n)
        y++;
      else
        x++;
    } else if (y == n) {
      if (x < n)
        x++;
      else
        y--;
    } else if (x == n) {
      if (y > 0)
        y--;
      else
        x--;
    } else if (y == 0) {
      if (x > 0)
        x--;
      else
        y++;
    }
  }
  l = min(l, ll);
  cout << l;
  return 0;
}
