#include <bits/stdc++.h>
using namespace std;
vector<int> vi;
int n, t;
int vie = 0;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> t;
vi.push_back(0);
for (int i = 0; i < floor(n/2); ++i) {
int cur = ((i*(-2)+n)*4)-4;
vi.push_back(vie+cur)
vie = cur;
}
for (int i = 0; i < t; ++i) {
int x, y;
cin >> y >> x;
int up = y-1;
int bottom = n-y;
int left = x-1;
int right = n-x;
int closest = min(up, min(bottom, min(left, right)));
int nth = closest+1;
int result = vi[closest];
int side = n-(2*closest);
if (closest == left) {
cout << result+y-nth+1;
continue;
}
result += side;
if (closest == bottom) {
cout << result+(x-nth);
continue;
}
result += side-1;
if (closest == right) {
cout << result+n+y-closest;
continue;
}
result += side-1;
if (closest == up) {
cout << result+(n-x)-mins;
}
}
}