#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  int c = 0;
  int x = x1, y = y1;
  while (1) {
    if (y == 0) {
      while (x > 0) {
        if (x == x2 and y == y2) break;
        x--;
        c++;
      }
    }
    if (x == 0) {
      while (y < n) {
        if (x == x2 and y == y2) break;
        y++;
        c++;
      }
    }
    if (y == n) {
      while (x < n) {
        if (x == x2 and y == y2) break;
        x++;
        c++;
      }
    }
    if (x == n) {
      while (y > 0) {
        if (x == x2 and y == y2) break;
        y--;
        c++;
      }
    }
    if (x == x2 and y == y2) break;
  }
  int ac = 0;
  x = x1, y = y1;
  while (1) {
    if (x == x2 and y == y2) break;
    if (y == n) {
      while (x > 0) {
        if (x == x2 and y == y2) break;
        x--;
        ac++;
      }
    }
    if (x == n) {
      while (y < n) {
        if (x == x2 and y == y2) break;
        y++;
        ac++;
      }
    }
    if (y == 0) {
      while (x < n) {
        if (x == x2 and y == y2) break;
        x++;
        ac++;
      }
    }
    if (x == 0) {
      while (y > 0) {
        if (x == x2 and y == y2) break;
        y--;
        ac++;
      }
    }
  }
  cout << min(c, ac) << "\n";
  return 0;
}
