Meg the Rabbit decided to do something nice, specifically — to determine the shortest distance between two points on the surface of our planet. But Meg... what can you say, she wants everything simple. So, she already regards our planet as a two-dimensional circle. No, wait, it's even worse — as a square of side n. Thus, the task has been reduced to finding the shortest path between two dots on a square (the path should go through the square sides). To simplify the task let us consider the vertices of the square to lie at points whose coordinates are: (0, 0), (n, 0), (0, n) and (n, n).

Input

The single line contains 5 space-separated integers: n, x1, y1, x2, y2 (1 ≤ n ≤ 1000, 0 ≤ x1, y1, x2, y2 ≤ n) which correspondingly represent a side of the square, the coordinates of the first point and the coordinates of the second point. It is guaranteed that the points lie on the sides of the square.

Output

You must print on a single line the shortest distance between the points.

Examples

Input

2 0 0 1 0


Output

1


Input

2 0 1 2 1


Output

4


Input

100 0 0 100 100


Output

200
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b);
long long cross_prod(long long ax, long long ay, long long bx, long long by,
                     long long cx, long long cy);
long long sum_digit(long long A);
long long get_mask(long long x);
long long get_nr(string &S, int pos, int lg);
bool cmp_pair_ii1(pair<int, int> A, pair<int, int> B);
bool cmp_i2(int A, int B);
string next_word(string &S, int &pos);
long long rise(long long x, long long p);
class SegmentTree {
 public:
  vector<int> V;
  void init(int dim);
  int query(int start, int end, int pos, int node);
  void build(int start, int end, int node);
};
int n, a, b, x, y;
int main() {
  cin >> n >> a >> b >> x >> y;
  if ((a <= b && x <= y) || (a >= b && x >= y)) {
    cout << abs(a - x) + abs(b - y);
  } else {
    cout << min(a + b + x + y, 4 * n - (a + b + x + y));
  }
  return 0;
}
bool cmp_pair_ii1(pair<int, int> A, pair<int, int> B) {
  return A.first < B.first;
}
bool cmp_i2(int A, int B) { return A > B; }
long long gcd(long long a, long long b) { return (b ? gcd(b, a % b) : a); }
long long cross_prod(long long ax, long long ay, long long bx, long long by,
                     long long cx, long long cy) {
  return (bx - ax) * (cy - ay) - (by - ay) * (cx - ax);
}
long long sum_digit(long long A) {
  long long sum = 0;
  do {
    sum += A % 10;
    A /= 10;
  } while (A);
  return sum;
}
long long get_mask(long long x) {
  long long mask = 0, c;
  while (x) {
    c = x % 10;
    x /= 10;
    if (c == 4 || c == 7) {
      mask = mask * 10 + c;
    }
  }
  return mask;
}
void SegmentTree::init(int dim) { V.resize((dim + 1) << 2); }
void SegmentTree::build(int start, int end, int node) {
  V[node] = end - start + 1;
  if (start == end) {
    return;
  }
  int mid;
  mid = (start + end) >> 1;
  build(start, mid, (node << 1));
  build(mid + 1, end, ((node << 1) | 1));
}
int SegmentTree::query(int start, int end, int pos, int node) {
  --V[node];
  if (start == end) return end;
  int L, R;
  L = node << 1;
  R = L | 1;
  int mid;
  mid = (start + end) >> 1;
  if (pos <= V[L]) {
    return query(start, mid, pos, L);
  } else {
    return query(mid + 1, end, pos - V[L], R);
  }
}
long long get_nr(string &S, int pos, int lg) {
  long long nr = 0;
  while (lg) {
    nr = nr * 10 + (S[pos] - '0');
    ++pos;
    --lg;
  }
  return nr;
}
string next_word(string &S, int &pos) {
  int pos_l, pos_sp;
  if (S[S.length() - 1] != ' ') {
    S += ' ';
  }
  pos_l = S.find_first_not_of(" ", pos);
  if (pos_l == -1) {
    pos = -1;
    return "";
  }
  pos_sp = S.find_first_of(" ", pos_l);
  pos = pos_sp;
  return S.substr(pos_l, pos_sp - pos_l);
}
long long rise(long long x, long long p) {
  if (p == 1) {
    return x;
  }
  long long res = rise(x, p / 2);
  res %= 1000000007;
  if (p & 1) {
    return (((res * res) % 1000000007) * x) % 1000000007;
  } else {
    return ((res * res) % 1000000007);
  }
}
