#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#define ll long long
using namespace std;
ll gne(ll n, ll x, ll y) {
vector<ll> dists;
dists.push_back(y);
dists.push_back(n-y-1);
dists.push_back(x);
dists.push_back(n-x-1);
ll m = *min_element(dists.begin(), dists.end());
return m;
}
ll oddsum(ll n) {
n = n + 1;
n = n / 2;
return n*n;
}
ll getltop(ll n, ll l) {
//cout << "n: " << n << "\n";
//cout << oddsum(5) << "\n";
return 4*(oddsum(n-1)-oddsum(n-1-2*l)) + 1;
}
ll test(ll n, ll x, ll y) {
ll l = gne(n,x,y);
ll ltop = getltop(n,l);
ll llen = n-2*l-1;
//cout << "l: " << l << "ltop: " << ltop << " llen: " << llen <<"\n";
if (x == l){
//cout << "left";
return ltop + (y - l);
}
if ((y-l) == llen) {
//cout << "bot";
return ltop + llen + (x-l);
}
if ((x-l) == llen) {
//cout << "right";
return ltop + 3*llen - (y-l);
}
if (y == l) {
//cout << "top";
return ltop + 4*llen - (x-l);
}
//cout << "FAIL\n";
return 0;
}
ll main() {
ll n, t;
cin >> n >> t;
for(ll i=0; i<t; i++){
ll x, y;
cin >> y >> x;
cout << test(n,x-1,y-1) << "\n";
}
return 0;
}