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;
const double EPS = 1e-9;
template <typename tn>
class BIT {
 public:
  BIT(vector<tn> list) {
    tree = vector<tn>(list.size() + 1, 0);
    int i = 1;
    for (auto it : list) tree[i++] = it;
    for (int indx = 1; indx < tree.size(); indx++) {
      int indx2 = indx + (indx & -indx);
      if (indx2 < tree.size()) tree[indx2] += tree[indx];
    }
  }
  BIT(tn n) { tree = vector<tn>(n, 0); }
  int prefix_query(int indx) {
    int sum = 0;
    while (indx > 0) {
      sum += tree[indx];
      indx -= (indx & -indx);
    }
    return sum;
  }
  int ranged_query(int to, int from) {
    if (to < from) swap(to, from);
    return prefix_query(to) - prefix_query(from - 1);
  }
  void update(int indx, int x) {
    while (indx < tree.size()) {
      tree[indx] += x;
      indx += (indx & -indx);
    }
  }

 private:
  vector<tn> tree;
};
int calc(int n) {
  int res = 1;
  for (int i = 0; i < n; i++) {
    res *= 2;
    res %= 100000;
  }
  return res - 1;
}
struct PT {
  double x, y;
  PT() {}
  PT(double x, double y) : x(x), y(y) {}
  PT(const PT &p) : x(p.x), y(p.y) {}
  PT operator+(const PT &p) const { return PT(x + p.x, y + p.y); }
  PT operator-(const PT &p) const { return PT(x - p.x, y - p.y); }
  PT operator*(double c) const { return PT(x * c, y * c); }
  PT operator/(double c) const { return PT(x / c, y / c); }
  bool operator==(const PT &p) const { return x == p.x && y == p.y; }
};
double dot(PT p, PT q) { return p.x * q.x + p.y * q.y; }
double dist2D_sqr(PT p, PT q) { return dot(p - q, p - q); }
double dist2D(PT p, PT q) { return sqrt(dot(p - q, p - q)); }
double cross(PT p, PT q) { return p.x * q.y - p.y * q.x; }
bool PointOnSegment(PT p, PT a, PT b) {
  if (fabs(cross(p - b, a - b)) < EPS) {
    if (p.x < min(a.x, b.x) || p.x > max(a.x, b.x)) return false;
    if (p.y < min(a.y, b.y) || p.y > max(a.y, b.y)) return false;
    return true;
  }
  return false;
}
vector<PT> str;
vector<int> v[6], res;
bool visited[6];
void bfs(int start, int end, int cur) {
  for (int i = 0; i < v[start].size(); i++) {
    int pos = v[start][i];
    if (!visited[pos]) {
      if (v[start][i] == end) {
        res.push_back(cur + abs(str[start].x - str[v[start][i]].x) +
                      abs(str[start].y - str[v[start][i]].y));
        return;
      }
      visited[v[start][i]] = true;
      bfs(v[start][i], end,
          cur + abs(str[start].x - str[v[start][i]].x) +
              abs(str[start].y - str[v[start][i]].y));
      visited[pos] = false;
    }
  }
}
int main() {
  int n;
  cin >> n;
  PT a(0, 0), b(n, 0), c(n, n), d(0, n);
  str.push_back(a);
  str.push_back(b);
  str.push_back(c);
  str.push_back(d);
  v[0].push_back(1);
  v[0].push_back(3);
  v[1].push_back(0);
  v[1].push_back(2);
  v[2].push_back(3);
  v[2].push_back(1);
  v[3].push_back(0);
  v[3].push_back(2);
  int x1, y1, x2, y2, start, end;
  start = end = 10;
  cin >> x1 >> y1 >> x2 >> y2;
  PT X(x1, y1), Y(x2, y2);
  str.push_back(X);
  str.push_back(Y);
  for (int i = 0; i < 4; i++) {
    if (X == str[i]) start = i;
    if (Y == str[i]) end = i;
  }
  if (start == 10) {
    start = 4;
    bool flag = 0;
    for (int i = 0; i < 4; i++) {
      for (int j = 0; j < 4; j++) {
        if (PointOnSegment(X, str[i], str[j])) {
          v[4].push_back(i);
          v[4].push_back(j);
          flag = 1;
          break;
        }
        if (flag) break;
      }
      if (flag) break;
    }
  }
  if (end == 10) {
    end = 5;
    bool flag = 0;
    for (int i = 0; i < 4; i++) {
      for (int j = 0; j < 4; j++) {
        if (PointOnSegment(Y, str[i], str[j])) {
          v[i].push_back(5);
          v[j].push_back(5);
          if (start == 4)
            if ((v[4][0] == i && v[4][1] == j) ||
                (v[4][0] == j && v[4][1] == i))
              v[4].push_back(5);
          flag = 1;
          break;
        }
      }
      if (flag) break;
    }
  }
  if (start != end) {
    visited[start] = true;
    bfs(start, end, 0);
    sort(res.begin(), res.end());
    cout << res[0] << endl;
  } else
    cout << 0 << endl;
  return 0;
}
