#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
const int inf = 1e9;
const int mo = 998244353;
vector<pair<int, int>> G[N];
inline void link(int u, int v, int w) {
  G[u].push_back({v, w});
  G[v].push_back({u, w});
}
int dis[N];
bool vis[N];
void dijkstra(int n, int pos) {
  for (auto i = (1); i <= (n); ++i) dis[i] = inf, vis[i] = 0;
  priority_queue<pair<int, int>, vector<pair<int, int>>,
                 greater<pair<int, int>>>
      pq;
  pq.push({0, pos});
  dis[pos] = 0;
  while (!pq.empty()) {
    pair<int, int> top = pq.top();
    pq.pop();
    int u = top.second, d = top.first;
    if (vis[u]) continue;
    for (auto e : G[u]) {
      int v = e.first;
      if (dis[v] > d + e.second) {
        dis[v] = d + e.second;
        pq.push({dis[v], v});
      }
    }
  }
}
pair<int, int> a[N], b[N], f, c[N];
int main() {
  int ww, n;
  cin >> ww >> n;
  n++;
  cin >> a[1].first >> b[1].first;
  a[1].second = b[1].second = 1;
  cin >> f.first >> f.second;
  c[1] = {a[1].first, b[1].first};
  for (auto i = (2); i <= (n); ++i) {
    a[i].second = b[i].second = i;
    cin >> a[i].first >> b[i].first;
    c[i].first = a[i].first, c[i].second = b[i].first;
  }
  sort(a + 1, a + 1 + n);
  sort(b + 1, b + 1 + n);
  for (auto i = (1); i <= (n - 1); ++i) {
    link(a[i].second, a[i + 1].second, a[i + 1].first - a[i].first);
    link(b[i].second, b[i + 1].second, b[i + 1].first - b[i].first);
  }
  dijkstra(n, 1);
  int ans = 2e9;
  for (auto i = (1); i <= (n); ++i) {
    ans = min(ans,
              dis[i] + abs(f.first - c[i].first) + abs(f.second - c[i].second));
  }
  cout << ans;
  return 0;
}
