#include <iostream>
#include <vector>
using namespace std;
int main()
{
long long n, t, x = 1, i, y;
int p = 0;
cin >> n >> t;
vector<vector<long long>> m(1);
m.resize(n);
for (i = 0; i < m.size(); i++) m[i].resize(n);
int b = 0;
n -= 1;
while (x <= pow(n + 1, 2))
{
for (i = 0; i <= n; i++) {
if (b == 0) {
if (m[i][p] == 0) m[i][p] = x;
else x--;
}
else if (b == 1) {
if (m[n - p][i] == 0) m[n - p][i] = x;
else x--;
}
else if (b == 2) {
if (m[n - i][n - p] == 0) m[n - i][n - p] = x;
else x--;
}
else if (b == 3) {
if (m[p][n - i] == 0) m[p][n - i] = x;
else x--;
}
x++;
}
if (b == 3) {
b = 0;
p++;
}
else b++;
if (p > n) p = n;
}
vector<long long> l;
for (i = 0; i < t; i++)
{
cin >> x >> y;
l.push_back(m[x - 1][y - 1]);
}
for (i = 0; i < t; i++)
{
cout << l[i] << "\n";
}
}