#include <bits/stdc++.h>
using namespace std;
int a, x, y, xx, yy;
int main() {
  cin >> a >> x >> y >> xx >> yy;
  if (abs(x - xx) == a)
    cout << a + min(2 * a - y - yy, y + yy);
  else if (abs(y - yy) == a)
    cout << a + min(2 * a - x - xx, x + xx);
  else
    cout << abs(xx - x) + abs(yy - y);
  return 0;
}
