#include <bits/stdc++.h>
using pii = std::pair<long long, long long>;
using namespace std;
const long long maxm = 1e5 + 5;
long long n, m, sx, sy, fx, fy, x[maxm], y[maxm];
set<long long> xvals, yvals;
set<long long> visitedx, visitedy;
map<long long, vector<long long>> adjvals[2];
map<long long, long long> dist[2];
void add_adjacent(
    long long curdist, long long curx, long long cury,
    priority_queue<pair<long long, pii>, vector<pair<long long, pii>>,
                   greater<pair<long long, pii>>>& pq) {
  auto itx = xvals.find(curx);
  auto ity = yvals.find(cury);
  assert(itx != xvals.end() && ity != yvals.end());
  if (next(itx) != xvals.end()) {
    long long adddist = abs(*next(itx) - curx);
    if (curdist + adddist < dist[0][*next(itx)]) {
      dist[0][*next(itx)] = curdist + adddist;
      pq.push({dist[0][*next(itx)], {0, *next(itx)}});
    }
  }
  if (itx != xvals.begin()) {
    long long adddist = abs(*prev(itx) - curx);
    if (curdist + adddist < dist[0][*prev(itx)]) {
      dist[0][*prev(itx)] = curdist + adddist;
      pq.push({dist[0][*prev(itx)], {0, *prev(itx)}});
    }
  }
  if (next(ity) != yvals.end()) {
    long long adddist = abs(*next(ity) - cury);
    if (curdist + adddist < dist[1][*next(ity)]) {
      dist[1][*next(ity)] = curdist + adddist;
      pq.push({dist[1][*next(ity)], {1, *next(ity)}});
    }
  }
  if (ity != yvals.begin()) {
    long long adddist = abs(*prev(ity) - cury);
    if (curdist + adddist < dist[1][*prev(ity)]) {
      dist[1][*prev(ity)] = curdist + adddist;
      pq.push({dist[1][*prev(ity)], {1, *prev(ity)}});
    }
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  cin >> sx >> sy >> fx >> fy;
  xvals.insert(sx);
  yvals.insert(sy);
  x[0] = sx;
  y[0] = sy;
  adjvals[0][sx].push_back(0);
  adjvals[1][sy].push_back(0);
  for (long long i = 1; i <= m; i++) {
    cin >> x[i] >> y[i];
    xvals.insert(x[i]);
    yvals.insert(y[i]);
    adjvals[0][x[i]].push_back(i);
    adjvals[1][y[i]].push_back(i);
  }
  for (auto v : xvals) dist[0][v] = 2e18;
  for (auto v : yvals) dist[1][v] = 2e18;
  priority_queue<pair<long long, pii>, vector<pair<long long, pii>>,
                 greater<pair<long long, pii>>>
      pq;
  dist[0][sx] = 0;
  dist[1][sy] = 0;
  pq.push({0, {0, sx}});
  pq.push({0, {1, sy}});
  while (!pq.empty()) {
    pair<long long, pii> cur = pq.top();
    pq.pop();
    if (cur.first != dist[cur.second.first][cur.second.second]) continue;
    for (auto v : adjvals[cur.second.first][cur.second.second]) {
      if (cur.first < dist[1][y[v]]) {
        dist[1][y[v]] = cur.first;
        pq.push({cur.first, {1, y[v]}});
      }
      if (cur.first < dist[0][x[v]]) {
        dist[0][x[v]] = cur.first;
        pq.push({cur.first, {0, x[v]}});
      }
      add_adjacent(cur.first, x[v], y[v], pq);
    }
  }
  long long ans = 2e18;
  for (long long i = 0; i <= m; i++)
    ans = min(ans, min(dist[0][x[i]], dist[1][y[i]]) + abs(fx - x[i]) +
                       abs(fy - y[i]));
  cout << ans << "\n";
  return 0;
}
