#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
using ll = long long;
using ii = pair<int, int>;
const int N = 2e5 + 5, LG = 19, MOD = 1e9 + 7;
using mat = vector<vector<long double>>;
void printCase(int cs) { cout << "Case #" << cs << ": "; }
int x[100005];
int y[100005];
int n, m;
int sx, sy, fx, fy;
ll dist[100005];
set<ii> st1, st2;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  cin >> sx >> sy >> fx >> fy;
  for (int i = 1; i < m + 1; i++) {
    cin >> x[i] >> y[i];
    st1.insert({x[i], i});
    st2.insert({y[i], i});
  }
  priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>>
      pq;
  pq.push({0ll, 0});
  memset(dist, 63, sizeof dist);
  dist[0] = 0;
  x[0] = sx;
  y[0] = sy;
  while (pq.size()) {
    auto cur = pq.top().second;
    ll d = pq.top().first;
    pq.pop();
    if (dist[cur] < d) continue;
    auto goRight = st1.upper_bound(make_pair(x[cur], cur));
    auto goLeft = st1.lower_bound(make_pair(x[cur], cur));
    auto goUp = st2.upper_bound(make_pair(y[cur], cur));
    auto goDown = st2.lower_bound(make_pair(y[cur], cur));
    if (goRight != st1.end()) {
      int idx = goRight->second;
      if (dist[idx] > dist[cur] + abs(x[cur] - x[idx])) {
        dist[idx] = dist[cur] + abs(x[cur] - x[idx]);
        pq.push({dist[idx], idx});
      }
    }
    if (goLeft != st1.begin()) {
      int idx = (--goLeft)->second;
      if (dist[idx] > dist[cur] + abs(x[cur] - x[idx])) {
        dist[idx] = dist[cur] + abs(x[cur] - x[idx]);
        pq.push({dist[idx], idx});
      }
    }
    if (goUp != st2.end()) {
      int idx = goUp->second;
      if (dist[idx] > dist[cur] + abs(y[cur] - y[idx])) {
        dist[idx] = dist[cur] + abs(y[cur] - y[idx]);
        pq.push({dist[idx], idx});
      }
    }
    if (goDown != st2.begin()) {
      int idx = (--goDown)->second;
      if (dist[idx] > dist[cur] + abs(y[cur] - y[idx])) {
        dist[idx] = dist[cur] + abs(y[cur] - y[idx]);
        pq.push({dist[idx], idx});
      }
    }
  }
  ll ans = LLONG_MAX;
  for (int i = 0; i < m + 1; i++) {
    ans = min(ans, abs(x[i] - fx) + abs(y[i] - fy) + dist[i]);
  }
  cout << ans << '\n';
  return 0;
}
