#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long INF64 = 3e18 + 1;
const char invdir[]{'L', 'U', 'R', 'D'};
const char dir[]{'R', 'D', 'L', 'U'};
const int dx[]{0, 1, 0, -1};
const int dy[]{1, 0, -1, 0};
unsigned get_seed() {
  unsigned seed = chrono::system_clock::now().time_since_epoch().count();
  return seed;
}
const int MOD = 1000000007;
int attrx[100555];
int attry[100555];
vector<int> G[100555];
int viz[100555];
void dfs(int n, int color) {
  viz[n] = color;
  for (auto el : G[n]) {
    if (!viz[el]) {
      viz[el] = color;
      dfs(el, color);
    }
  }
}
vector<int> y_col[100555];
vector<int> x_col[100555];
int cost[500555];
vector<pair<int, int>> Gcol[500555];
void dijkstra(int start) {
  set<pair<int, int>> pq;
  pq.insert({0, start});
  while (!pq.empty()) {
    pair<int, int> top = *pq.begin();
    pq.erase(pq.begin());
    if (cost[top.second] < top.first) {
      continue;
    }
    cost[top.second] = top.first;
    for (auto it : Gcol[top.second]) {
      if (cost[top.second] + it.second < cost[it.first]) {
        cost[it.first] = cost[top.second] + it.second;
        pq.insert({cost[it.first], it.first});
      }
    }
  }
}
int solve() {
  int n, m;
  cin >> n;
  cin >> m;
  cin >> attrx[1] >> attry[1];
  int fx, fy;
  cin >> fx >> fy;
  m++;
  for (int i = 2; i <= m; ++i) {
    cin >> attrx[i] >> attry[i];
  }
  vector<pair<int, int>> samex, samey;
  for (int i = 1; i <= m; ++i) {
    samex.push_back({attrx[i], i});
    samey.push_back({attry[i], i});
  }
  sort(samex.begin(), samex.end());
  sort(samey.begin(), samey.end());
  for (int i = 0; i < samex.size(); ++i) {
    if (i > 0) {
      if (samex[i].first == samex[i - 1].first) {
        G[samex[i].second].push_back(samex[i - 1].second);
        G[samex[i - 1].second].push_back(samex[i].second);
      }
    }
  }
  for (int i = 0; i < samey.size(); ++i) {
    if (i > 0) {
      if (samey[i].first == samey[i - 1].first) {
        G[samey[i].second].push_back(samey[i - 1].second);
        G[samey[i - 1].second].push_back(samey[i].second);
      }
    }
  }
  int col = 1;
  for (int i = 1; i <= m; ++i) {
    if (!viz[i]) {
      dfs(i, col);
      col++;
    }
  }
  col--;
  for (int i = 1; i <= m; ++i) {
    x_col[viz[i]].push_back(attrx[i]);
    y_col[viz[i]].push_back(attry[i]);
  }
  vector<int> xs, ys;
  for (int i = 1; i <= m; ++i) {
    xs.push_back(attrx[i]);
    ys.push_back(attry[i]);
  }
  sort(xs.begin(), xs.end());
  sort(ys.begin(), ys.end());
  xs.erase(unique(xs.begin(), xs.end()), xs.end());
  ys.erase(unique(ys.begin(), ys.end()), ys.end());
  map<int, int> Mx;
  for (int i = 0; i < xs.size(); ++i) {
    Mx[xs[i]] = i;
    if (i > 0) {
      Gcol[i].push_back({i - 1, xs[i] - xs[i - 1]});
      Gcol[i - 1].push_back({i, xs[i] - xs[i - 1]});
    }
  }
  map<int, int> My;
  for (int i = 0; i < ys.size(); ++i) {
    My[ys[i]] = i + xs.size();
    if (i > 0) {
      Gcol[i + xs.size()].push_back({i - 1 + xs.size(), ys[i] - ys[i - 1]});
      Gcol[i - 1 + xs.size()].push_back({i + xs.size(), ys[i] - ys[i - 1]});
    }
  }
  for (int i = 1; i <= col; ++i) {
    sort(x_col[i].begin(), x_col[i].end());
    sort(y_col[i].begin(), y_col[i].end());
    x_col[i].erase(unique(x_col[i].begin(), x_col[i].end()), x_col[i].end());
    y_col[i].erase(unique(y_col[i].begin(), y_col[i].end()), y_col[i].end());
    for (int j = 0; j < x_col[i].size(); ++j) {
      if (j > 0) {
        Gcol[Mx[x_col[i][j]]].push_back({Mx[x_col[i][j - 1]], 0});
        Gcol[Mx[x_col[i][j - 1]]].push_back({Mx[x_col[i][j]], 0});
      }
    }
    for (int j = 0; j < y_col[i].size(); ++j) {
      if (j > 0) {
        Gcol[My[y_col[i][j]]].push_back({My[y_col[i][j - 1]], 0});
        Gcol[My[y_col[i][j - 1]]].push_back({My[y_col[i][j]], 0});
      }
    }
    Gcol[My[y_col[i][0]]].push_back({Mx[x_col[i][0]], 0});
    Gcol[Mx[x_col[i][0]]].push_back({My[y_col[i][0]], 0});
  }
  for (int i = 0; i < xs.size(); ++i) {
  }
  for (int i = 0; i < ys.size(); ++i) {
  }
  for (int i = 0; i <= xs.size() + ys.size(); ++i) {
    cost[i] = 1e9;
  }
  cost[Mx[attrx[1]]] = 0;
  dijkstra(Mx[attrx[1]]);
  int ans = 2000000555;
  for (int i = 1; i <= m; ++i) {
    ans =
        min(ans, cost[Mx[attrx[i]]] + abs(attrx[i] - fx) + abs(attry[i] - fy));
  }
  for (int i = 0; i < xs.size() + ys.size(); ++i) {
  }
  cout << ans << "\n";
  return 0;
}
int main() {
  cout << setprecision(16);
  cin.tie(0);
  std::ios_base::sync_with_stdio(0);
  int T = 1;
  int i = 1;
  while (T--) {
    i++;
    solve();
  }
  return 0;
}
