#include <bits/stdc++.h>
using namespace std;
int x[100005], y[100005];
set<pair<int, int>> h, v;
int main() {
  int n, m;
  cin >> m >> n;
  vector<long long> dis(n + 1, 1e18);
  int tx, ty;
  cin >> x[0] >> y[0] >> tx >> ty;
  for (int i = 1; i <= n; ++i) {
    cin >> x[i] >> y[i];
    h.emplace(x[i], i);
    v.emplace(y[i], i);
  }
  set<pair<long long, int>> pq;
  pq.emplace(dis[0] = 0, 0);
  set<int> done;
  while (pq.size()) {
    auto u = pq.begin()->second;
    pq.erase(pq.begin());
    if (done.count(u)) continue;
    done.insert(u);
    h.insert({x[u], u});
    if (h.begin()->second != u) {
      auto i = (--h.find({x[u], u}))->second;
      long long d = dis[u] + x[u] - x[i];
      if (d < dis[i]) {
        pq.emplace(dis[i] = d, i);
      }
    }
    if (h.rbegin()->second != u) {
      auto i = (++h.find({x[u], u}))->second;
      long long d = dis[u] + x[i] - x[u];
      if (d < dis[i]) {
        pq.emplace(dis[i] = d, i);
      }
    }
    h.erase({x[u], u});
    v.insert({y[u], u});
    if (v.begin()->second != u) {
      auto i = (--v.find({y[u], u}))->second;
      long long d = dis[u] + y[u] - y[i];
      if (d < dis[i]) {
        pq.emplace(dis[i] = d, i);
      }
    }
    if (v.rbegin()->second != u) {
      auto i = (++v.find({y[u], u}))->second;
      long long d = dis[u] + y[i] - y[u];
      if (d < dis[i]) {
        pq.emplace(dis[i] = d, i);
      }
    }
    v.erase({y[u], u});
  }
  long long ans = LLONG_MAX;
  for (int i = 0; i <= n; ++i)
    ans = min(ans, dis[i] + abs(x[i] - tx) + abs(y[i] - ty));
  cout << ans << endl;
}
