#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
struct node {
  int val, id;
  bool flag;
  bool operator<(const node& a) const {
    if (val != a.val) return val < a.val;
    if (id != a.id) return id < a.id;
    return flag < a.flag;
  }
};
inline int dist(pair<int, int> a, pair<int, int> b) {
  return abs(a.first - b.first) + abs(a.second - b.second);
}
set<node> s;
set<int> fn[2];
vector<vector<int> > d(2);
vector<vector<vector<int> > > dir(2);
vector<vector<bool> > vis(2);
vector<int> xx, yy;
inline int g(int x, bool flag) {
  return (flag ? (int)(lower_bound(xx.begin(), xx.end(), x) - xx.begin())
               : (int)(lower_bound(yy.begin(), yy.end(), x) - yy.begin()));
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m, sx, sy, fx, fy;
  cin >> n >> m >> sx >> sy >> fx >> fy;
  pair<int, int> f = {fx, fy};
  vector<pair<int, int> > v(m);
  dir[0].resize(m, vector<int>());
  dir[1].resize(m, vector<int>());
  d[0].resize(m, INT_MAX);
  d[1].resize(m, INT_MAX);
  vis[0].resize(m, 0);
  vis[1].resize(m, 0);
  for (pair<int, int>& p : v) {
    cin >> p.first >> p.second;
    xx.push_back(p.first);
    yy.push_back(p.second);
  }
  sort(xx.begin(), xx.end());
  sort(yy.begin(), yy.end());
  int sz = unique(xx.begin(), xx.end()) - xx.begin();
  xx.resize(sz);
  sz = unique(yy.begin(), yy.end()) - yy.begin();
  yy.resize(sz);
  for (pair<int, int> p : v) {
    int di = dist(p, f);
    p.first = g(p.first, 1);
    p.second = g(p.second, 0);
    fn[1].insert(p.first);
    fn[0].insert(p.second);
    dir[1][p.first].push_back(p.second);
    dir[0][p.second].push_back(p.first);
    for (int i = 0; i < 2; i++) {
      if (di < d[i][(i == 1 ? p.first : p.second)]) {
        node curr;
        curr.flag = i;
        curr.id = (i == 1 ? p.first : p.second);
        curr.val = d[i][(i == 1 ? p.first : p.second)];
        s.erase(curr);
        curr.val = d[i][(i == 1 ? p.first : p.second)] = di;
        s.insert(curr);
      }
    }
  }
  while (!s.empty()) {
    node curr = *s.begin(), tmp;
    s.erase(s.begin());
    int id = curr.id, di = curr.val;
    bool flag = curr.flag;
    curr.id = (flag ? xx[id] : yy[id]);
    fn[flag].erase(id);
    tmp.flag = !flag;
    if (!vis[flag][id]) {
      vis[flag][id] = 1;
      for (int x : dir[flag][id]) {
        if (di < d[!flag][x]) {
          tmp.id = x;
          tmp.val = d[!flag][x];
          s.erase(tmp);
          tmp.val = d[!flag][x] = di;
          s.insert(tmp);
        }
      }
    }
    tmp.flag = flag;
    auto it = fn[flag].upper_bound(id);
    if (it != fn[flag].end()) {
      int inn = *it, nn = (flag ? xx[inn] : yy[inn]);
      if (abs(curr.id - nn) + di < d[flag][inn]) {
        tmp.id = inn;
        tmp.val = d[flag][inn];
        s.erase(tmp);
        tmp.val = d[flag][inn] = abs(curr.id - nn) + di;
        s.insert(tmp);
      }
    }
    it = fn[flag].lower_bound(id);
    if (it != fn[flag].begin() && !fn[flag].empty()) {
      it--;
      int inn = *it, nn = (flag ? xx[inn] : yy[inn]);
      if (abs(curr.id - nn) + di < d[flag][inn]) {
        tmp.id = inn;
        tmp.val = d[flag][inn];
        s.erase(tmp);
        tmp.val = d[flag][inn] = abs(curr.id - nn) + di;
        s.insert(tmp);
      }
    }
  }
  int res = abs(sx - fx) + abs(sy - fy);
  for (pair<int, int> p : v) {
    res = min(res, abs(p.first - sx) + d[1][g(p.first, 1)]);
    res = min(res, abs(p.second - sy) + d[0][g(p.second, 0)]);
  }
  cout << res << '\n';
}
