#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;

struct node {
    int x, y;
}a[MAXN];

map <int, set <int> > mp[2];
set <int> :: iterator it;
bool vis[2][MAXN];
int ans[MAXN];

int main() {
    //freopen("in", "r", stdin);
    int n, m, p;
    scanf("%d%d%d", &m, &n, &p);
    for (int i = 1; i <= p; i++) {
        scanf("%d%d", &a[i].x, &a[i].y);
        mp[0][a[i].y - a[i].x].insert(i);
        mp[1][a[i].x + a[i].y].insert(i);
    }
    int k = 0, b = 0, nx = 0, ny = 0, nt = 0;
    vis[0][0] = true;
    memset(ans, -1, sizeof(ans));
    while (true) {
        for (it = mp[k][b].begin(); it != mp[k][b].end(); it++) {
            //if (ans[*it] != -1) continue;
            int x = a[*it].x, y = a[*it].y;
            ans[*it] = nt + abs(x - nx);
            if (k == 0) mp[1][x + y].erase(*it);
            else mp[0][y - x].erase(*it);
        }
        int kk = k == 0 ? 1 : -1;
        int xx[4] = {0, -b / kk, m, (n - b) / kk};
        int yy[4] = {b, 0, kk * m + b, n};
        int tx = nx, ty = ny;
        for (int i = 0; i < 4; i++) {
            if (xx[i] >= 0 && xx[i] <= m && yy[i] >= 0 && yy[i] <= n && xx[i] != tx && yy[i] != ty) {
                nt += abs(xx[i] - tx);
                nx = xx[i];
                ny = yy[i];
            }
        }
        //printf("%d %d\n", nx, ny);
        if ((nx == m && ny == n) || (nx == 0 && ny == 0) || (nx == m && ny == 0) || (nx == 0 && ny == n)) break;
        kk = -kk;
        b = ny - kk * nx;
        k = kk == 1 ? 0 : 1;
        //if (vis[k][b]) break;
        //vis[k][b] = true;
    }
    for (int i = 1; i <= p; i++)
        printf("%d\n", ans[i]);
    return 0;
}


#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define ll long long
#define db double
#define inf 1000000000000LL
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define swap(T, a, b) ({T ttt = a; a = b; b = ttt;})
ll Ans, tmp, t, tA;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
void exgcd(ll a, ll b, ll &d, ll &x, ll &y)
{
   if (b == 0) { d = a; x = 1; y = 0; }
   else { exgcd(b, a%b, d, y, x); y -= x * (a / b); }
}
ll cal(ll a, ll b, ll c)
{
   ll d, x, y;
   if (c == 0) x = y = 0;
   else
   {
      if (std::abs(c) % gcd(a, b) != 0) return -inf;
      d = gcd(a, b); a /= d; b /= d; c /= d;
      exgcd(a, b, d, x, y);
      if (a*x+b*y==-1) { x *= -1; y *= -1; }
      x *= c; y *= -c;
      ll k = min(x/b, y/a); k = max(k, 0);
      x -= k*b; y -= k*a;
      while (x < 0 || y < 0) { x += b; y += a; }
   }
   if (x >= 0 && y >= 0) return x;
   return -inf;
}
int n, m, k, x, y;
int main()
{
   scanf("%d%d%d", &n, &m, &k);
   tmp = (ll)n * m * gcd(n, m);
   for (int i = 1; i <= k; i++)
   {
      scanf("%d%d", &x, &y);
      Ans = inf;

      tA = cal(2*n, 2*m, y-x); t = tA*2*n+x;
      if (t >= 0 && t <= tmp) Ans = min(Ans, t);

      tA = cal(2*n, 2*m, -y-x); t = tA*2*n+x;
      if (t >= 0 && t <= tmp) Ans = min(Ans, t);

      tA = cal(2*n, 2*m, x+y); t = tA*2*n-x;
      if (t >= 0 && t <= tmp) Ans = min(Ans, t);

      tA = cal(2*n, 2*m, x-y); t = tA*2*n-x;
      if (t >= 0 && t <= tmp) Ans = min(Ans, t);

      if (Ans == inf) Ans = -1;
      std::cout << Ans << std::endl;
   }
   return 0;
}


#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define ll long long
#define db double
#define inf 1000000000000LL
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define swap(T, a, b) ({T ttt = a; a = b; b = ttt;})
ll Ans, tmp, t, tA;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
void exgcd(ll a, ll b, ll &d, ll &x, ll &y)
{
   if (b == 0) { d = a; x = 1; y = 0; }
   else { exgcd(b, a%b, d, y, x); y -= x * (a / b); }
}
ll cal(ll a, ll b, ll c)
{
   ll d, x, y;
   if (c == 0) x = y = 0;
   else
   {
      if (std::abs(c) % gcd(a, b) != 0) return -inf;
      d = gcd(a, b); a /= d; b /= d; c /= d;
      exgcd(a, b, d, x, y);
      if (a*x+b*y==-1) { x *= -1; y *= -1; }
      x *= c; y *= -c;
      ll k = min(x/b, y/a); k = max(k, 0);
      x -= k*b; y -= k*a;
      while (x > 0 && y > 0) { x -= b; y += a; }
      while (x < 0 || y < 0) { x += b; y += a; }
   }
   if (x >= 0 && y >= 0) return x;
   return -inf;
}
int n, m, k, x, y;
int main()
{
   scanf("%d%d%d", &n, &m, &k);
   tmp = (ll)n * m * gcd(n, m);
   for (int i = 1; i <= k; i++)
   {
      scanf("%d%d", &x, &y);
      Ans = inf;

      tA = cal(2*n, 2*m, y-x); t = tA*2*n+x;
      if (t >= 0 && t <= tmp) Ans = min(Ans, t);

      tA = cal(2*n, 2*m, -y-x); t = tA*2*n+x;
      if (t >= 0 && t <= tmp) Ans = min(Ans, t);

      tA = cal(2*n, 2*m, x+y); t = tA*2*n-x;
      if (t >= 0 && t <= tmp) Ans = min(Ans, t);

      tA = cal(2*n, 2*m, x-y); t = tA*2*n-x;
      if (t >= 0 && t <= tmp) Ans = min(Ans, t);

      if (Ans == inf) Ans = -1;
      std::cout << Ans << std::endl;
   }
   return 0;
}


#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define ll long long
#define db double
#define inf 1000000000000LL
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define swap(T, a, b) ({T ttt = a; a = b; b = ttt;})
ll Ans, tmp, t, tA;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
void exgcd(ll a, ll b, ll &d, ll &x, ll &y)
{
   if (b == 0) { d = a; x = 1; y = 0; }
   else { exgcd(b, a%b, d, y, x); y -= x * (a / b); }
}
ll cal(ll a, ll b, ll c)
{
   ll d, x, y;
   if (c == 0) x = y = 0;
   else
   {
      if (std::abs(c) % gcd(a, b) != 0) return -inf;
      d = gcd(a, b); a /= d; b /= d; c /= d;
      exgcd(a, b, d, x, y);
      if (a*x+b*y==-1) { x *= -1; y *= -1; }
      x *= c; y *= -c;
      ll k = min(x/b, y/a); k = max(k, 0);
      x -= k*b; y -= k*a;
      if (x > 0 && y > 0) { x -= b; y -= a; }
      if (x < 0 || y < 0) { x += b; y += a; }
   }
   if (x >= 0 && y >= 0) return x;
   return -inf;
}
int n, m, k, x, y;
int main()
{
   scanf("%d%d%d", &n, &m, &k);
   tmp = (ll)n * m * gcd(n, m);
   for (int i = 1; i <= k; i++)
   {
      scanf("%d%d", &x, &y);
      Ans = inf;

      tA = cal(2*n, 2*m, y-x); t = tA*2*n+x;
      if (t >= 0 && t <= tmp) Ans = min(Ans, t);

      tA = cal(2*n, 2*m, -y-x); t = tA*2*n+x;
      if (t >= 0 && t <= tmp) Ans = min(Ans, t);

      tA = cal(2*n, 2*m, x+y); t = tA*2*n-x;
      if (t >= 0 && t <= tmp) Ans = min(Ans, t);

      tA = cal(2*n, 2*m, x-y); t = tA*2*n-x;
      if (t >= 0 && t <= tmp) Ans = min(Ans, t);

      if (Ans == inf) Ans = -1;
      std::cout << Ans << std::endl;
   }
   return 0;
}


#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define ll long long
#define db double
#define inf 1000000000000LL
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define swap(T, a, b) ({T ttt = a; a = b; b = ttt;})
ll Ans, tmp, t, tA;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
void exgcd(ll a, ll b, ll &d, ll &x, ll &y)
{
   if (b == 0) { d = a; x = 1; y = 0; }
   else { exgcd(b, a%b, d, y, x); y -= x * (a / b); }
}
ll cal(ll a, ll b, ll c)
{
   ll d, x, y;
   if (c == 0) x = y = 0;
   else
   {
      if (std::abs(c) % gcd(a, b) != 0) return -inf;
      d = gcd(a, b); a /= d; b /= d; c /= d;
      exgcd(a, b, d, x, y);
      if (a*x+b*y==-1) { x *= -1; y *= -1; }
      x *= c; y *= -c;
      ll k = min(x/b + (x%b!=0?1:0), y/a + (y%a!=0?1:0));
      x -= k*b; y -= k*a;
      if (x > 0 && y > 0) { x -= b; y -= a; }
      if (x < 0 || y < 0) { x += b; y += a; }
   }
   if (x >= 0 && y >= 0) return x;
   return -inf;
}
int n, m, k, x, y;
int main()
{
   scanf("%d%d%d", &n, &m, &k);
   tmp = (ll)n * m * gcd(n, m);
   for (int i = 1; i <= k; i++)
   {
      scanf("%d%d", &x, &y);
      Ans = inf;

      tA = cal(2*n, 2*m, y-x); t = tA*2*n+x;
      if (t >= 0 && t <= tmp) Ans = min(Ans, t);

      tA = cal(2*n, 2*m, -y-x); t = tA*2*n+x;
      if (t >= 0 && t <= tmp) Ans = min(Ans, t);

      tA = cal(2*n, 2*m, x+y); t = tA*2*n-x;
      if (t >= 0 && t <= tmp) Ans = min(Ans, t);

      tA = cal(2*n, 2*m, x-y); t = tA*2*n-x;
      if (t >= 0 && t <= tmp) Ans = min(Ans, t);

      if (Ans == inf) Ans = -1;
      std::cout << Ans << std::endl;
   }
   return 0;
}


#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define ll long long
#define db double
#define inf 1000000000000LL
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define swap(T, a, b) ({T ttt = a; a = b; b = ttt;})
ll Ans, tmp, t, tA;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
void exgcd(ll a, ll b, ll &d, ll &x, ll &y)
{
   if (b == 0) { d = a; x = 1; y = 0; }
   else { exgcd(b, a%b, d, y, x); y -= x * (a / b); }
}
ll cal(ll a, ll b, ll c)
{
   ll d, x, y;
   if (c == 0) x = y = 0;
   else
   {
      if (c % gcd(a, b) != 0) return -inf;
      d = gcd(a, b); a /= d; b /= d; c /= d;
      exgcd(a, b, d, x, y);
      x *= c; y *= -c;
      ll k = min(x/b, y/a); k = max(k, 0);
      x -= k*b; y -= k*a;
      if (x > 0 && y > 0) { x -= b; y -= a; }
      if (x < 0 || y < 0) { x += b; y += a; }
   }
   if (x >= 0 && y >= 0) return x;
   return -inf;
}
int n, m, k, x, y;
int main()
{
   scanf("%d%d%d", &n, &m, &k);
   tmp = (ll)n * m * gcd(n, m);
   for (int i = 1; i <= k; i++)
   {
      scanf("%d%d", &x, &y);
      Ans = inf;

      tA = cal(2*n, 2*m, y-x); t = tA*2*n+x;
      if (t >= 0 && t <= tmp) Ans = min(Ans, t);

      tA = cal(2*n, 2*m, -y-x); t = tA*2*n+x;
      if (t >= 0 && t <= tmp) Ans = min(Ans, t);

      tA = cal(2*n, 2*m, x+y); t = tA*2*n-x;
      if (t >= 0 && t <= tmp) Ans = min(Ans, t);

      tA = cal(2*n, 2*m, x-y); t = tA*2*n-x;
      if (t >= 0 && t <= tmp) Ans = min(Ans, t);

      if (Ans == inf) Ans = -1;
      std::cout << Ans << std::endl;
   }
   return 0;
}


#include <bits/stdc++.h>
#define endl '\n'
using namespace std;

const int maxM = 1e5 + 5;

int x, y, n, m, current_time, curr_time, k, xi, yi, dr_x, dr_y, dl_x, dl_y, ur_x, ur_y, ul_x, ul_y;
long long min_time;
map<int, int> time1[maxM][4];
string dir;

bool is_corner(int a, int b)
{
    if(a == 0 && b == 0) return true;
    else if(a == 0 && b == m) return true;
    else if(a == n && b == 0) return true;
    else if(a == n && b == m) return true;

    return false;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>n>>m;

    dir = "dr";
    time1[0][0][0] = 0;
    do
    {
        if(dir == "dr")
        {
            if(y + (n - x) < m)
            {
                dir = "ur";
                y += (n - x);
              	current_time += (n - x);
			  	x = n;
            }
            else
            {
                dir = "dl";
                x += (m - y);
              	current_time += (m - y);
			  	y = m;
            }
        }
        else if(dir == "dl")
        {
            if(y - (n - x) >= 0)
            {
                dir = "ul";
                y -= (n - x);
               	current_time += (n - x);
			  	x = n;
            }
            else
            {
                dir = "dr";
                x += y;
               	current_time += y;
			   	y = 0;
            }
        }
        else if(dir == "ur")
        {
            if(x + y <= m)
            {
                dir = "dr";
                y += x;
                current_time += x;
				x = 0;
            }
            else
            {
                dir = "ul";
                x -= (m - y);
                current_time += (m - y);
				y = m;
            }
        }
        else if(dir == "ul")
        {
            if(y - x >= 0)
            {
                dir = "dl";
                y -= x;
				current_time += x;
                x = 0;
            }
            else
            {
                dir = "ur";
                x -= y;
              	current_time += y;
				y = 0;
            }
        }

        if(dir == "dr")
        {
            time1[x][y][0] = current_time;
        }
        else if(dir == "dl")
        {
            time1[x][y][1] = current_time;
        }
        else if(dir == "ur")
        {
            time1[x][y][2] = current_time;
        }
        else if(dir == "ul")
        {
            time1[x][y][3] = current_time;
        }
    }
    while(!is_corner(x, y));

    cin>>k;
    for(int i = 0; i < k; i++)
    {
        cin>>xi>>yi;

        if(yi + (n - xi) < m)
        {
            dr_x = n;
            dr_y = yi + (n - xi);
        }
        else
        {
            dr_x = xi + (m - yi);
            dr_y = m;
        }

        if(yi - (n - xi) >= 0)
        {
            dl_x = n;
            dl_y = yi - (n - xi);
        }
        else
        {
            dl_x = xi + yi;
            dl_y = 0;
        }

        if(yi - xi >= 0)
        {
            ul_x = 0;
            ul_y = yi - xi;
        }
        else
        {
            ul_x = xi - yi;
            ul_y = 0;
        }

        if(xi + yi <= m)
        {
            ur_x = 0;
            ur_y = xi + yi;
        }
        else
        {
            ur_x = xi - (m - yi);
            ur_y = m;
        }

		/*
		cout<<dr_x<<" "<<dr_y<<" "<<time1[dr_x][dr_y][3]<<endl;
		cout<<dl_x<<" "<<dl_y<<" "<<time1[dl_x][dl_y][2]<<endl;
		cout<<ur_x<<" "<<ur_y<<" "<<time1[ur_x][ur_y][1]<<endl;
		cout<<ul_x<<" "<<ul_y<<" "<<time1[ul_x][ul_y][0]<<endl;
	 	cout<<time1[3][3][2]<<endl;
		*/

        min_time = n * m + 1;
        if((ul_x == 0 && ul_y == 0) || (time1[ul_x][ul_y][0]))
        {
            curr_time = time1[ul_x][ul_y][0] + abs(ul_x - xi);
            if(curr_time < min_time) min_time = curr_time;
        }
        if(time1[ur_x][ur_y][1])
        {
            curr_time = time1[ur_x][ur_y][1] + abs(ur_x - xi);
            if(curr_time < min_time) min_time = curr_time;
        }
        if(time1[dl_x][dl_y][2])
        {
            curr_time = time1[dl_x][dl_y][2] + abs(dl_x - xi);
            if(curr_time < min_time) min_time = curr_time;
        }
        if(time1[dr_x][dr_y][3])
        {
            curr_time = time1[dr_x][dr_y][3] + abs(dr_x - xi);
            if(curr_time < min_time) min_time = curr_time;
        }

   		if(min_time == n * m + 1) cout<<-1<<endl;
        else cout<<min_time<<endl;
    }

    return 0;
}


#include <bits/stdc++.h>
#define endl '\n'
using namespace std;

const int maxN = 1e5 + 5;

int x, y, n, m, current_time, curr_time, k, xi, yi, dr_x, dr_y, dl_x, dl_y, ur_x, ur_y, ul_x, ul_y;
long long min_time;
map<int, long long> time1[4][maxN];
string dir;

bool is_corner(int a, int b)
{
    if(a == 0 && b == 0) return true;
    else if(a == 0 && b == m) return true;
    else if(a == n && b == 0) return true;
    else if(a == n && b == m) return true;

    return false;
}

int main()
{
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);

    cin>>n>>m;

    dir = "dr";
    time1[0][0][0] = 0;
    do
    {
		if(x == 99 && y == 72) cout<<x<<" "<<y<<endl;
        if(dir == "dr")
        {
            if(y + (n - x) <= m)
            {
                dir = "ur";
                y += (n - x);
              	current_time += (n - x);
			  	x = n;
            }
            else
            {
                dir = "dl";
                x += (m - y);
              	current_time += (m - y);
			  	y = m;
            }
        }
        else if(dir == "dl")
        {
            if(y - (n - x) >= 0)
            {
                dir = "ul";
                y -= (n - x);
               	current_time += (n - x);
			  	x = n;
            }
            else
            {
                dir = "dr";
                x += y;
               	current_time += y;
			   	y = 0;
            }
        }
        else if(dir == "ur")
        {
            if(x + y <= m)
            {
                dir = "dr";
                y += x;
                current_time += x;
				x = 0;
            }
            else
            {
                dir = "ul";
                x -= (m - y);
                current_time += (m - y);
				y = m;
            }
        }
        else if(dir == "ul")
        {
            if(y - x >= 0)
            {
                dir = "dl";
                y -= x;
				current_time += x;
                x = 0;
            }
            else
            {
                dir = "ur";
                x -= y;
              	current_time += y;
				y = 0;
            }
        }

        if(dir == "dr")
        {
            time1[0][x][y] = current_time;
        }
        else if(dir == "dl")
        {
            time1[1][x][y] = current_time;
        }
        else if(dir == "ur")
        {
            time1[2][x][y] = current_time;
        }
        else if(dir == "ul")
        {
            time1[3][x][y] = current_time;
        }
    }
    while(!is_corner(x, y));

    cin>>k;
    for(int i = 0; i < k; i++)
    {
        cin>>xi>>yi;

        if(yi + (n - xi) <= m)
        {
            dr_x = n;
            dr_y = yi + (n - xi);
        }
        else
        {
            dr_x = xi + (m - yi);
            dr_y = m;
        }

        if(yi - (n - xi) >= 0)
        {
            dl_x = n;
            dl_y = yi - (n - xi);
        }
        else
        {
            dl_x = xi + yi;
            dl_y = 0;
        }

        if(yi - xi >= 0)
        {
            ul_x = 0;
            ul_y = yi - xi;
        }
        else
        {
            ul_x = xi - yi;
            ul_y = 0;
        }

        if(xi + yi <= m)
        {
            ur_x = 0;
            ur_y = xi + yi;
        }
        else
        {
            ur_x = xi - (m - yi);
            ur_y = m;
        }

		/**
		cout<<dr_x<<" "<<dr_y<<" "<<time1[dr_x][dr_y][3]<<endl;
		cout<<dl_x<<" "<<dl_y<<" "<<time1[dl_x][dl_y][2]<<endl;
		cout<<ur_x<<" "<<ur_y<<" "<<time1[ur_x][ur_y][1]<<endl;
		cout<<ul_x<<" "<<ul_y<<" "<<time1[ul_x][ul_y][0]<<endl;
		*/

        min_time = n * m + 1;
        if((ul_x == 0 && ul_y == 0) || (time1[0][ul_x][ul_y]))
        {
            curr_time = time1[0][ul_x][ul_y] + abs(ul_x - xi);
            if(curr_time < min_time) min_time = curr_time;
        }
        if(time1[1][ur_x][ur_y])
        {
            curr_time = time1[1][ur_x][ur_y] + abs(ur_x - xi);
            if(curr_time < min_time) min_time = curr_time;
        }
        if(time1[2][dl_x][dl_y])
        {
            curr_time = time1[2][dl_x][dl_y] + abs(dl_x - xi);
            if(curr_time < min_time) min_time = curr_time;
        }
        if(time1[3][dr_x][dr_y])
        {
            curr_time = time1[3][dr_x][dr_y] + abs(dr_x - xi);
            if(curr_time < min_time) min_time = curr_time;
        }

   		if(min_time == n * m + 1) cout<<-1<<endl;
        else cout<<min_time<<endl;
    }

    return 0;
}


#include <bits/stdc++.h>
#define endl '\n'
using namespace std;

const int maxN = 1e5 + 5;

int x, y, n, m, current_time, curr_time, k, xi, yi, dr_x, dr_y, dl_x, dl_y, ur_x, ur_y, ul_x, ul_y;
long long min_time;
map<int, int> time1[4][maxN];
string dir;

bool is_corner(int a, int b)
{
    if(a == 0 && b == 0) return true;
    else if(a == 0 && b == m) return true;
    else if(a == n && b == 0) return true;
    else if(a == n && b == m) return true;

    return false;
}

int main()
{
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);

    cin>>n>>m;

    dir = "dr";
    time1[0][0][0] = 0;
    do
    {
		if(x == 99 && y == 72) cout<<x<<" "<<y<<endl;
        if(dir == "dr")
        {
            if(y + (n - x) <= m)
            {
                dir = "ur";
                y += (n - x);
              	current_time += (n - x);
			  	x = n;
            }
            else
            {
                dir = "dl";
                x += (m - y);
              	current_time += (m - y);
			  	y = m;
            }
        }
        else if(dir == "dl")
        {
            if(y - (n - x) >= 0)
            {
                dir = "ul";
                y -= (n - x);
               	current_time += (n - x);
			  	x = n;
            }
            else
            {
                dir = "dr";
                x += y;
               	current_time += y;
			   	y = 0;
            }
        }
        else if(dir == "ur")
        {
            if(x + y <= m)
            {
                dir = "dr";
                y += x;
                current_time += x;
				x = 0;
            }
            else
            {
                dir = "ul";
                x -= (m - y);
                current_time += (m - y);
				y = m;
            }
        }
        else if(dir == "ul")
        {
            if(y - x >= 0)
            {
                dir = "dl";
                y -= x;
				current_time += x;
                x = 0;
            }
            else
            {
                dir = "ur";
                x -= y;
              	current_time += y;
				y = 0;
            }
        }

        if(dir == "dr")
        {
            time1[0][x][y] = current_time;
        }
        else if(dir == "dl")
        {
            time1[1][x][y] = current_time;
        }
        else if(dir == "ur")
        {
            time1[2][x][y] = current_time;
        }
        else if(dir == "ul")
        {
            time1[3][x][y] = current_time;
        }
    }
    while(!is_corner(x, y));

    cin>>k;
    for(int i = 0; i < k; i++)
    {
        cin>>xi>>yi;

        if(yi + (n - xi) <= m)
        {
            dr_x = n;
            dr_y = yi + (n - xi);
        }
        else
        {
            dr_x = xi + (m - yi);
            dr_y = m;
        }

        if(yi - (n - xi) >= 0)
        {
            dl_x = n;
            dl_y = yi - (n - xi);
        }
        else
        {
            dl_x = xi + yi;
            dl_y = 0;
        }

        if(yi - xi >= 0)
        {
            ul_x = 0;
            ul_y = yi - xi;
        }
        else
        {
            ul_x = xi - yi;
            ul_y = 0;
        }

        if(xi + yi <= m)
        {
            ur_x = 0;
            ur_y = xi + yi;
        }
        else
        {
            ur_x = xi - (m - yi);
            ur_y = m;
        }

		/**
		cout<<dr_x<<" "<<dr_y<<" "<<time1[dr_x][dr_y][3]<<endl;
		cout<<dl_x<<" "<<dl_y<<" "<<time1[dl_x][dl_y][2]<<endl;
		cout<<ur_x<<" "<<ur_y<<" "<<time1[ur_x][ur_y][1]<<endl;
		cout<<ul_x<<" "<<ul_y<<" "<<time1[ul_x][ul_y][0]<<endl;
		*/

        min_time = n * m + 1;
        if((ul_x == 0 && ul_y == 0) || (time1[0][ul_x][ul_y]))
        {
            curr_time = time1[0][ul_x][ul_y] + abs(ul_x - xi);
            if(curr_time < min_time) min_time = curr_time;
        }
        if(time1[1][ur_x][ur_y])
        {
            curr_time = time1[1][ur_x][ur_y] + abs(ur_x - xi);
            if(curr_time < min_time) min_time = curr_time;
        }
        if(time1[2][dl_x][dl_y])
        {
            curr_time = time1[2][dl_x][dl_y] + abs(dl_x - xi);
            if(curr_time < min_time) min_time = curr_time;
        }
        if(time1[3][dr_x][dr_y])
        {
            curr_time = time1[3][dr_x][dr_y] + abs(dr_x - xi);
            if(curr_time < min_time) min_time = curr_time;
        }

   		if(min_time == n * m + 1) cout<<-1<<endl;
        else cout<<min_time<<endl;
    }

    return 0;
}


#include <bits/stdc++.h>
#define endl '\n'
using namespace std;

const int maxN = 1e5 + 5;

long long x, y, n, m, current_time, curr_time, k, xi, yi, dr_x, dr_y, dl_x, dl_y, ur_x, ur_y, ul_x, ul_y;
long long min_time;
map<int, long long> time1[4][maxN];
string dir;

bool is_corner(int a, int b)
{
    if(a == 0 && b == 0) return true;
    else if(a == 0 && b == m) return true;
    else if(a == n && b == 0) return true;
    else if(a == n && b == m) return true;

    return false;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>n>>m;

    dir = "dr";
    time1[0][0][0] = 0;
    do
    {
		if(x == 99 && y == 72) cout<<x<<" "<<y<<endl;
        if(dir == "dr")
        {
            if(y + (n - x) <= m)
            {
                dir = "ur";
                y += (n - x);
              	current_time += (n - x);
			  	x = n;
            }
            else
            {
                dir = "dl";
                x += (m - y);
              	current_time += (m - y);
			  	y = m;
            }
        }
        else if(dir == "dl")
        {
            if(y - (n - x) >= 0)
            {
                dir = "ul";
                y -= (n - x);
               	current_time += (n - x);
			  	x = n;
            }
            else
            {
                dir = "dr";
                x += y;
               	current_time += y;
			   	y = 0;
            }
        }
        else if(dir == "ur")
        {
            if(x + y <= m)
            {
                dir = "dr";
                y += x;
                current_time += x;
				x = 0;
            }
            else
            {
                dir = "ul";
                x -= (m - y);
                current_time += (m - y);
				y = m;
            }
        }
        else if(dir == "ul")
        {
            if(y - x >= 0)
            {
                dir = "dl";
                y -= x;
				current_time += x;
                x = 0;
            }
            else
            {
                dir = "ur";
                x -= y;
              	current_time += y;
				y = 0;
            }
        }

        if(dir == "dr")
        {
            time1[0][x][y] = current_time;
        }
        else if(dir == "dl")
        {
            time1[1][x][y] = current_time;
        }
        else if(dir == "ur")
        {
            time1[2][x][y] = current_time;
        }
        else if(dir == "ul")
        {
            time1[3][x][y] = current_time;
        }
    }
    while(!is_corner(x, y));

    cin>>k;
    for(int i = 0; i < k; i++)
    {
        cin>>xi>>yi;

        if(yi + (n - xi) <= m)
        {
            dr_x = n;
            dr_y = yi + (n - xi);
        }
        else
        {
            dr_x = xi + (m - yi);
            dr_y = m;
        }

        if(yi - (n - xi) >= 0)
        {
            dl_x = n;
            dl_y = yi - (n - xi);
        }
        else
        {
            dl_x = xi + yi;
            dl_y = 0;
        }

        if(yi - xi >= 0)
        {
            ul_x = 0;
            ul_y = yi - xi;
        }
        else
        {
            ul_x = xi - yi;
            ul_y = 0;
        }

        if(xi + yi <= m)
        {
            ur_x = 0;
            ur_y = xi + yi;
        }
        else
        {
            ur_x = xi - (m - yi);
            ur_y = m;
        }

        min_time = n * m + 1;
        if((ul_x == 0 && ul_y == 0) || (time1[0][ul_x][ul_y]))
        {
            curr_time = time1[0][ul_x][ul_y] + abs(ul_x - xi);
            if(curr_time < min_time) min_time = curr_time;
        }
        if(time1[1][ur_x][ur_y])
        {
            curr_time = time1[1][ur_x][ur_y] + abs(ur_x - xi);
            if(curr_time < min_time) min_time = curr_time;
        }
        if(time1[2][dl_x][dl_y])
        {
            curr_time = time1[2][dl_x][dl_y] + abs(dl_x - xi);
            if(curr_time < min_time) min_time = curr_time;
        }
        if(time1[3][dr_x][dr_y])
        {
            curr_time = time1[3][dr_x][dr_y] + abs(dr_x - xi);
            if(curr_time < min_time) min_time = curr_time;
        }

   		if(min_time == n * m + 1) cout<<-1<<endl;
        else cout<<min_time<<endl;
    }

    return 0;
}


#include <bits/stdc++.h>
#define endl '\n'
using namespace std;

const int maxM = 1e5 + 5;

int x, y, n, m, current_time, curr_time, k, xi, yi, dr_x, dr_y, dl_x, dl_y, ur_x, ur_y, ul_x, ul_y;
long long min_time;
map<int, int> time1[maxM][4];
string dir;

bool is_corner(int a, int b)
{
    if(a == 0 && b == 0) return true;
    else if(a == 0 && b == m) return true;
    else if(a == n && b == 0) return true;
    else if(a == n && b == m) return true;

    return false;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>n>>m;

    dir = "dr";
    time1[0][0][0] = 0;
    do
    {
        if(dir == "dr")
        {
            if(y + (n - x) < m)
            {
                dir = "ur";
                y += (n - x);
              	current_time += (n - x);
			  	x = n;
            }
            else
            {
                dir = "dl";
                x += (m - y);
              	current_time += (m - y);
			  	y = m;
            }
        }
        else if(dir == "dl")
        {
            if(y - (n - x) >= 0)
            {
                dir = "ul";
                y -= (n - x);
               	current_time += (n - x);
			  	x = n;
            }
            else
            {
                dir = "dr";
                x += y;
               	current_time += y;
			   	y = 0;
            }
        }
        else if(dir == "ur")
        {
            if(x + y <= m)
            {
                dir = "dr";
                y += x;
                current_time += x;
				x = 0;
            }
            else
            {
                dir = "ul";
                x -= (m - y);
                current_time += (m - y);
				y = m;
            }
        }
        else if(dir == "ul")
        {
            if(y - x >= 0)
            {
                dir = "dl";
                y -= x;
				current_time += x;
                x = 0;
            }
            else
            {
                dir = "ur";
                x -= y;
              	current_time += y;
				  y = 0;
            }
        }

        if(dir == "dr")
        {
            time1[x][y][0] = current_time;
        }
        else if(dir == "dl")
        {
            time1[x][y][1] = current_time;
        }
        else if(dir == "ur")
        {
            time1[x][y][2] = current_time;
        }
        else if(dir == "ul")
        {
            time1[x][y][3] = current_time;
        }
    }
    while(!is_corner(x, y));

    cin>>k;
    for(int i = 0; i < k; i++)
    {
        cin>>xi>>yi;

        if(yi + (n - xi) < m)
        {
            dr_x = n;
            dr_y = yi + (n - xi);
        }
        else
        {
            dr_x = xi + (m - yi);
            dr_y = m;
        }

        if(yi - (n - xi) >= 0)
        {
            dl_x = n;
            dl_y = yi - (n - xi);
        }
        else
        {
            dl_x = xi + yi;
            dl_y = 0;
        }

        if(yi - xi >= 0)
        {
            ul_x = 0;
            ul_y = yi - xi;
        }
        else
        {
            ul_x = xi - yi;
            ul_y = 0;
        }

        if(xi + yi <= m)
        {
            ur_x = 0;
            ur_y = xi + yi;
        }
        else
        {
            ur_x = xi - (m - yi);
            ur_y = m;
        }

		/*
		cout<<dr_x<<" "<<dr_y<<" "<<time1[dr_x][dr_y][3]<<endl;
		cout<<dl_x<<" "<<dl_y<<" "<<time1[dl_x][dl_y][2]<<endl;
		cout<<ur_x<<" "<<ur_y<<" "<<time1[ur_x][ur_y][1]<<endl;
		cout<<ul_x<<" "<<ul_y<<" "<<time1[ul_x][ul_y][0]<<endl;
	 	cout<<time1[3][3][2]<<endl;
		*/

        min_time = n * m;
        if((ul_x == 0 && ul_y == 0) || (time1[ul_x][ul_y][0]))
        {
            curr_time = time1[ul_x][ul_y][0] + abs(ul_x - xi);
            if(curr_time < min_time) min_time = curr_time;
        }
        if(time1[ur_x][ur_y][1])
        {
            curr_time = time1[ur_x][ur_y][1] + abs(ur_x - xi);
            if(curr_time < min_time) min_time = curr_time;
        }
        if(time1[dl_x][dl_y][2])
        {
            curr_time = time1[dl_x][dl_y][2] + abs(dl_x - xi);
            if(curr_time < min_time) min_time = curr_time;
        }
        if(time1[dr_x][dr_y][3])
        {
            curr_time = time1[dr_x][dr_y][3] + abs(dr_x - xi);
            if(curr_time < min_time) min_time = curr_time;
        }

   		if(min_time == n * m) cout<<-1<<endl;
        else cout<<min_time<<endl;
    }

    return 0;
}


#include <bits/stdc++.h>
#define endl '\n'
using namespace std;

const int maxN = 1e5 + 5;

long long x, y, n, m, current_time, curr_time, k, xi, yi, dr_x, dr_y, dl_x, dl_y, ur_x, ur_y, ul_x, ul_y;
long long min_time;
map<int, long long> time1[4][maxN];
string dir;

bool is_corner(int a, int b)
{
    if(a == 0 && b == 0) return true;
    else if(a == 0 && b == m) return true;
    else if(a == n && b == 0) return true;
    else if(a == n && b == m) return true;

    return false;
}

int main()
{
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);

    cin>>n>>m;

    dir = "dr";
    time1[0][0][0] = 0;
    do
    {
		if(x == 99 && y == 72) cout<<x<<" "<<y<<endl;
        if(dir == "dr")
        {
            if(y + (n - x) <= m)
            {
                dir = "ur";
                y += (n - x);
              	current_time += (n - x);
			  	x = n;
            }
            else
            {
                dir = "dl";
                x += (m - y);
              	current_time += (m - y);
			  	y = m;
            }
        }
        else if(dir == "dl")
        {
            if(y - (n - x) >= 0)
            {
                dir = "ul";
                y -= (n - x);
               	current_time += (n - x);
			  	x = n;
            }
            else
            {
                dir = "dr";
                x += y;
               	current_time += y;
			   	y = 0;
            }
        }
        else if(dir == "ur")
        {
            if(x + y <= m)
            {
                dir = "dr";
                y += x;
                current_time += x;
				x = 0;
            }
            else
            {
                dir = "ul";
                x -= (m - y);
                current_time += (m - y);
				y = m;
            }
        }
        else if(dir == "ul")
        {
            if(y - x >= 0)
            {
                dir = "dl";
                y -= x;
				current_time += x;
                x = 0;
            }
            else
            {
                dir = "ur";
                x -= y;
              	current_time += y;
				y = 0;
            }
        }

        if(dir == "dr")
        {
            time1[0][x][y] = current_time;
        }
        else if(dir == "dl")
        {
            time1[1][x][y] = current_time;
        }
        else if(dir == "ur")
        {
            time1[2][x][y] = current_time;
        }
        else if(dir == "ul")
        {
            time1[3][x][y] = current_time;
        }
    }
    while(!is_corner(x, y));

    cin>>k;
    for(int i = 0; i < k; i++)
    {
        cin>>xi>>yi;

        if(yi + (n - xi) <= m)
        {
            dr_x = n;
            dr_y = yi + (n - xi);
        }
        else
        {
            dr_x = xi + (m - yi);
            dr_y = m;
        }

        if(yi - (n - xi) >= 0)
        {
            dl_x = n;
            dl_y = yi - (n - xi);
        }
        else
        {
            dl_x = xi + yi;
            dl_y = 0;
        }

        if(yi - xi >= 0)
        {
            ul_x = 0;
            ul_y = yi - xi;
        }
        else
        {
            ul_x = xi - yi;
            ul_y = 0;
        }

        if(xi + yi <= m)
        {
            ur_x = 0;
            ur_y = xi + yi;
        }
        else
        {
            ur_x = xi - (m - yi);
            ur_y = m;
        }

		/**
		cout<<dr_x<<" "<<dr_y<<" "<<time1[dr_x][dr_y][3]<<endl;
		cout<<dl_x<<" "<<dl_y<<" "<<time1[dl_x][dl_y][2]<<endl;
		cout<<ur_x<<" "<<ur_y<<" "<<time1[ur_x][ur_y][1]<<endl;
		cout<<ul_x<<" "<<ul_y<<" "<<time1[ul_x][ul_y][0]<<endl;
		*/

        min_time = n * m + 1;
        if((ul_x == 0 && ul_y == 0) || (time1[0][ul_x][ul_y]))
        {
            curr_time = time1[0][ul_x][ul_y] + abs(ul_x - xi);
            if(curr_time < min_time) min_time = curr_time;
        }
        if(time1[1][ur_x][ur_y])
        {
            curr_time = time1[1][ur_x][ur_y] + abs(ur_x - xi);
            if(curr_time < min_time) min_time = curr_time;
        }
        if(time1[2][dl_x][dl_y])
        {
            curr_time = time1[2][dl_x][dl_y] + abs(dl_x - xi);
            if(curr_time < min_time) min_time = curr_time;
        }
        if(time1[3][dr_x][dr_y])
        {
            curr_time = time1[3][dr_x][dr_y] + abs(dr_x - xi);
            if(curr_time < min_time) min_time = curr_time;
        }

   		if(min_time == n * m + 1) cout<<-1<<endl;
        else cout<<min_time<<endl;
    }

    return 0;
}


#include <complex>
#include <iostream>
#include <cstring>
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <bitset>
#define _USE_MATH_DEFINES
#include <math.h>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <assert.h>
using namespace std;

void smain();
clock_t start;
int main(){
    ios_base::sync_with_stdio(0);
#ifdef TASK
    freopen(TASK".in","rt",stdin);
    start = clock();
#endif
    cout.precision(12); cout << fixed;
    smain();
#ifdef TASK
    cerr << "\nTotal Execution Time: " << float( clock () - start ) /  CLOCKS_PER_SEC << endl;
#endif
    return 0;
}
#ifndef M_PI
#define M_PI 3.14159265358979311599796346854418516
#endif
#define forn(i,n) for (int i=0;i<n;i++)
#define rforn(i,n) for (int i=n-1;i>=0;i--)
#define int long long
#define LL long long
#define mp(a,b) make_pair(a,b)
#define INF 2305843009213693951LL
#define MOD 1000000007
#define EPS 1E-12
#define N 100003
/* --------- END TEMPLATE CODE --------- */

#define y0 asdsa

int gcd(int a, int b, int & x, int & y) {
	if (a == 0) {
		x = 0; y = 1;
		return b;
	}
	int x1, y1;
	int d = gcd(b%a, a, x1, y1);
	x = y1 - (b / a) * x1;
	y = x1;
	return d;
}

int n, m, x0, y0, g;

int solve(int x, int y) {
    if (x == y) return x;
    int c = x - y;
    if (c & 1) return INF;
    c /= 2;
    if (c % g != 0) return INF;
    int k2 = c / g * x0;
    int k1 = -c / g * y0;
    int b = -n / g, a = m / g;
    int r = k1 / a, l = - (k2 / b);
    while (k1 - r * a < 0 && l <= r) r -= 1;

    return x + 2 * (k1 - r * a) * n;
}

void smain() {
    int k;
    for (; cin >> n >> m >> k;) {
        g = gcd(m, n, x0, y0);
        int mt = n / g * m;
        // cout << mt << endl;
        // cout << x0 << ' ' << y0 << ' ' << g << endl;
        forn(i, k) {
            int x, y;
            cin >> x >> y;
            int res = INF;
            res = min(res, solve(x, y));
            res = min(res, solve(2 * n - x, y));
            res = min(res, solve(x, 2 * m - y));
            res = min(res, solve(2 * n - x, 2 * m - y));
            assert(res >= 0);
            if (res > mt) res = -1;
            cout << res << '\n';
        }
        cout << endl;
    }
}


#include <complex>
#include <iostream>
#include <cstring>
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <bitset>
#define _USE_MATH_DEFINES
#include <math.h>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <assert.h>
using namespace std;

void smain();
clock_t start;
int main(){
    ios_base::sync_with_stdio(0);
#ifdef TASK
    freopen(TASK".in","rt",stdin);
    start = clock();
#endif
    cout.precision(12); cout << fixed;
    smain();
#ifdef TASK
    cerr << "\nTotal Execution Time: " << float( clock () - start ) /  CLOCKS_PER_SEC << endl;
#endif
    return 0;
}
#ifndef M_PI
#define M_PI 3.14159265358979311599796346854418516
#endif
#define forn(i,n) for (int i=0;i<n;i++)
#define rforn(i,n) for (int i=n-1;i>=0;i--)
#define int __int128
#define LL long long
#define mp(a,b) make_pair(a,b)
#define INF 2305843009213693951LL
#define MOD 1000000007
#define EPS 1E-12
#define N 100003
/* --------- END TEMPLATE CODE --------- */

#define y0 asdsa

int gcd(int a, int b, int & x, int & y) {
	if (a == 0) {
		x = 0; y = 1;
		return b;
	}
	int x1, y1;
	int d = gcd(b%a, a, x1, y1);
	x = y1 - (b / a) * x1;
	y = x1;
	return d;
}

int n, m, x0, y0, g;

int solve(int x, int y) {
    if (x == y) return x;
    int c = x - y;
    if (c & 1) return INF;
    c /= 2;
    // int a = m, b = -n;
    if (c % g != 0) return INF;
    int k2 = c / g * x0;
    int k1 = -c / g * y0;
    int b = -n / g, a = m / g;
    int r = k1 / a, l = - (k2 / b);
    while (k2 + l * b < 0 && l <= r) l += 1;
    while (k1 - r * a < 0 && l <= r) r -= 1;
    if (l > r) return INF;

    return min(x + 2 * (k1 - l * a) * n, x + 2 * (k1 - r * a) * n);
}

void smain() {
    int k;
    for (; cin >> n >> m >> k;) {
        g = gcd(m, n, x0, y0);
        int mt = n / g * m;
        // cout << mt << endl;
        // cout << x0 << ' ' << y0 << ' ' << g << endl;
        forn(i, k) {
            int x, y;
            cin >> x >> y;
            int res = INF;
            res = min(res, solve(x, y));
            res = min(res, solve(2 * n - x, y));
            res = min(res, solve(x, 2 * m - y));
            res = min(res, solve(2 * n - x, 2 * m - y));
            if (res > mt) res = -1;
            cout << res << '\n';
        }
        cout << endl;
    }
}


#include <complex>
#include <iostream>
#include <cstring>
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <bitset>
#define _USE_MATH_DEFINES
#include <math.h>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <assert.h>
using namespace std;

void smain();
clock_t start;
int main(){
    ios_base::sync_with_stdio(0);
#ifdef TASK
    freopen(TASK".in","rt",stdin);
    start = clock();
#endif
    cout.precision(12); cout << fixed;
    smain();
#ifdef TASK
    cerr << "\nTotal Execution Time: " << float( clock () - start ) /  CLOCKS_PER_SEC << endl;
#endif
    return 0;
}
#ifndef M_PI
#define M_PI 3.14159265358979311599796346854418516
#endif
#define forn(i,n) for (int i=0;i<n;i++)
#define rforn(i,n) for (int i=n-1;i>=0;i--)
#define int long long
#define LL long long
#define mp(a,b) make_pair(a,b)
#define INF 2305843009213693951LL
#define MOD 1000000007
#define EPS 1E-12
#define N 100003
/* --------- END TEMPLATE CODE --------- */

#define y0 asdsa

int gcd(int a, int b, int & x, int & y) {
	if (a == 0) {
		x = 0; y = 1;
		return b;
	}
	int x1, y1;
	int d = gcd(b%a, a, x1, y1);
	x = y1 - (b / a) * x1;
	y = x1;
	return d;
}

int n, m, x0, y0, g;

int solve(int x, int y) {
    if (x == y) return x;
    int c = x - y;
    if (c & 1) return INF;
    c /= 2;
    // int a = m, b = -n;
    if (c % g != 0) return INF;
    int k2 = x0 * c / g;
    int k1 = -y0 * c / g;
    int b = -n / g, a = m / g;
    int r = k1 / a, l = - (k2 / b);
    while (k2 + l * b < 0 && l <= r) l += 1;
    while (k1 - r * a < 0 && l <= r) r -= 1;
    if (l > r) return INF;

    return min(x + 2 * (k1 - l * a) * n, x + 2 * (k1 - r * a) * n);
}

void smain() {
    int k;
    for (; cin >> n >> m >> k;) {
        g = gcd(m, n, x0, y0);
        int mt = n / g * m;
        // cout << mt << endl;
        // cout << x0 << ' ' << y0 << ' ' << g << endl;
        forn(i, k) {
            int x, y;
            cin >> x >> y;
            int res = INF;
            res = min(res, solve(x, y));
            res = min(res, solve(2 * n - x, y));
            res = min(res, solve(x, 2 * m - y));
            res = min(res, solve(2 * n - x, 2 * m - y));
            if (res > mt) res = -1;
            cout << res << '\n';
        }
        cout << endl;
    }
}


#pragma comment(linker, "/STACK:100000000")
#define _SCL_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include <algorithm>
#include <memory.h>
#include <iostream>
#include <iterator>
#include <ostream>
#include <iomanip>
#include <cstring>
#include <sstream>
#include <cassert>
#include <cstdlib>
#include <istream>
#include <fstream>
#include <climits>
#include <complex>
#include <memory>
#include <string>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef complex <ld> cd;

const bool db = false;

#define fs first
#define sd second
#define mp make_pair
#define pb push_back
#define ppb pop_back

#define inf 1000000007
#define nmax 100100
#define mmax 100100
#define eps 1e-12

unordered_set<int> answer;

pair<int, int> segments[nmax];

unordered_set<int> cur_seg;
vector<pair<int, pair<int, int > > > events;
int balance = 0;

bool check(int len,const int &number_of_segments, const int &need) {
	cur_seg.clear();
	events.clear();
	for (int id = 1; id <= number_of_segments; id++) {
		if (segments[id].second - segments[id].first + 1 >= len)
			events.push_back({ segments[id].first,{-1,id } }), events.push_back({ segments[id].second - len + 1,{1,id } });
	}
	balance = 0;
	sort(events.begin(), events.end());
	for (int id = 0; id < (int)events.size(); id++) {
		if (events[id].second.first < 0)
			balance++, cur_seg.insert(events[id].second.second);
		else balance--, cur_seg.erase(events[id].second.second);
		if (balance >= need) {
			answer = cur_seg;
			return true;
		}
	}
	return false;
}

int main() {
#ifdef Ahoma
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif // Ahoma
	ios::sync_with_stdio(0);
	int number_of_segments, need;
	cin >> number_of_segments >> need;
	for (int id = 1; id <= number_of_segments; id++)
		cin >> segments[id].first >> segments[id].second;
	int left_side = 0, right_side = 2 * inf, mid;
	while (left_side + 1 != right_side) {
		mid = (left_side + right_side) >> 1;
		if (check(mid, number_of_segments, need))
			left_side = mid;
		else right_side = mid;
	}
	if (check(right_side, number_of_segments, need)) {
		cout << right_side << '\n';
		for (auto elem : answer)
			cout << elem << ' ';
	}
	else if (check(left_side, number_of_segments, need)) {
		cout << left_side << '\n';
		for (auto elem : answer)
			cout << elem << ' ';
	}
	else {
		cout<<0<<'\n';
		for (int ident = 1; ident <= need; ident++)
			cout << ident << ' ';
	}
	return 0;
}


#pragma comment(linker, "/STACK:100000000")
#define _SCL_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include <algorithm>
#include <memory.h>
#include <iostream>
#include <iterator>
#include <ostream>
#include <iomanip>
#include <cstring>
#include <sstream>
#include <cassert>
#include <cstdlib>
#include <istream>
#include <fstream>
#include <climits>
#include <complex>
#include <memory>
#include <string>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef complex <ld> cd;

const bool db = false;

#define fs first
#define sd second
#define mp make_pair
#define pb push_back
#define ppb pop_back

#define inf 1000000007
#define nmax 100100
#define mmax 100100
#define eps 1e-12

unordered_set<int> answer;

int number_of_segments, need;

pair<int, int> segments[nmax];

bool check(int len) {
	unordered_set<int> cur_seg;
	vector<pair<int, pair<int, int > > > events;
	for (int id = 1; id <= number_of_segments; id++) {
		if (segments[id].second - segments[id].first + 1 >= len)
			events.push_back({ segments[id].first,{-1,id } }), events.push_back({ segments[id].second - len + 1,{1,id } });
	}
	sort(events.begin(), events.end());
	int balance = 0;
	for (int id = 0; id < (int)events.size(); id++) {
		if (events[id].second.first < 0)
			balance++, cur_seg.insert(events[id].second.second);
		else balance--, cur_seg.erase(events[id].second.second);
		if (balance >= need) {
			answer = cur_seg;
			return true;
		}
	}
	return false;
}

string bad_answer;

int main() {
#ifdef Ahoma
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif // Ahoma
	ios::sync_with_stdio(0);
	cin >> number_of_segments >> need;
	bad_answer += "0\n";
	for (int id = 1; id <= need; id++)
		bad_answer += to_string(id) + " ";
	for (int id = 1; id <= number_of_segments; id++)
		cin >> segments[id].first >> segments[id].second;
	int left_side = 0, right_side = inf, mid;
	while (left_side + 1 != right_side) {
		mid = (left_side + right_side) >> 1;
		if (check(mid))
			left_side = mid;
		else right_side = mid;
	}
	if (check(right_side)) {
		cout << right_side << '\n';
		for (auto elem : answer)
			cout << elem << ' ';
	}
	else if (check(left_side)) {
		cout << left_side << '\n';
		for (auto elem : answer)
			cout << elem << ' ';
	}
	else cout << bad_answer;
	return 0;
}


#pragma comment(linker, "/STACK:100000000")
#define _SCL_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include <algorithm>
#include <memory.h>
#include <iostream>
#include <iterator>
#include <ostream>
#include <iomanip>
#include <cstring>
#include <sstream>
#include <cassert>
#include <cstdlib>
#include <istream>
#include <fstream>
#include <climits>
#include <complex>
#include <memory>
#include <string>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef complex <ld> cd;

const bool db = false;

#define fs first
#define sd second
#define mp make_pair
#define pb push_back
#define ppb pop_back

#define inf 1000000007
#define nmax 100100
#define mmax 100100
#define eps 1e-12

unordered_set<int> answer;

pair<int, int> segments[nmax];

unordered_set<int> cur_seg;
vector<pair<int, pair<int, int > > > events;
int balance = 0;

bool check(int len,const int &number_of_segments, const int &need) {
	cur_seg.clear();
	events.clear();
	for (int id = 1; id <= number_of_segments; id++) {
		if (segments[id].second - segments[id].first + 1 >= len)
			events.push_back({ segments[id].first,{-1,id } }), events.push_back({ segments[id].second - len + 1,{1,id } });
	}
	balance = 0;
	sort(events.begin(), events.end());
	for (int id = 0; id < (int)events.size(); id++) {
		if (events[id].second.first < 0)
			balance++, cur_seg.insert(events[id].second.second);
		else balance--, cur_seg.erase(events[id].second.second);
		if (balance >= need) {
			answer = cur_seg;
			return true;
		}
	}
	return false;
}

string bad_answer;

int main() {
#ifdef Ahoma
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif // Ahoma
	ios::sync_with_stdio(0);
	int number_of_segments, need;
	cin >> number_of_segments >> need;
	for (int id = 1; id <= number_of_segments; id++)
		cin >> segments[id].first >> segments[id].second;
	int left_side = 0, right_side = 2 * inf, mid;
	while (left_side + 1 != right_side) {
		mid = (left_side + right_side) >> 1;
		if (check(mid, number_of_segments, need))
			left_side = mid;
		else right_side = mid;
	}
	if (check(right_side, number_of_segments, need)) {
		cout << right_side << '\n';
		for (auto elem : answer)
			cout << elem << ' ';
	}
	else if (check(left_side, number_of_segments, need)) {
		cout << left_side << '\n';
		for (auto elem : answer)
			cout << elem << ' ';
	}
	else {
		bad_answer += "0\n";
		for (int ident = 1; ident <= need; ident++)
			bad_answer += to_string(ident) + " ";
		cout << bad_answer;
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>

using namespace std;

#define inf 1000000007
#define nmax 100100
#define mmax 100100
#define eps 1e-12

set<int> answer;

int number_of_segments, need;

pair<int, int> segments[nmax];

vector<pair<int, pair<int, int > > > events;
int balance = 0;

inline bool check(const int &len,const bool &ans=false) {
	if (ans)
		answer.clear();
	events.clear();
	for (int id = 1; id <= number_of_segments; id++) {
		if (segments[id].second - segments[id].first + 1 >= len) {
			events.push_back({ segments[id].first,{ -1,id } });
			events.push_back({ segments[id].second - len + 1,{ 1,id } });
		}
	}
	balance = 0;
	sort(events.begin(), events.end());
	for (int id = 0; id < (int)events.size(); id++) {
		if (events[id].second.first < 0) {
			balance++;
			if (ans)
				answer.insert(events[id].second.second);
		}
		else {
			balance--;
			if (ans)
				answer.erase(events[id].second.second);
		}
		if (balance == need)
			return true;
	}
	return false;
}

int main() {
#ifdef Ahoma
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif // Ahoma
	scanf("%d %d\n", &number_of_segments, &need);
	int wtf_with_need = need;
	int left_side = 0, right_side = 0, mid;
	for (int id = 1; id <= number_of_segments; id++) {
		scanf("%d %d\n", &segments[id].first, &segments[id].second);
		right_side = max(right_side, segments[id].second - segments[id].first + 5);
	}
	while (left_side + 1 != right_side) {
		mid = (left_side + right_side) >> 1;
		if (check(mid))
			left_side = mid;
		else right_side = mid;
	}
	check(left_side, true);
	printf("%d\n", left_side);
	if (!left_side)
		for (int id = 1; id <= wtf_with_need; id++)
			answer.insert(id);
	for (auto elem : answer)
		printf("%d ", elem);
	return 0;
}


#pragma comment(linker, "/STACK:100000000")
#define _SCL_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#pragma GCC ostarimize("O500")
#define _USE_MATH_DEFINES
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include <algorithm>
#include <memory.h>
#include <iostream>
#include <iterator>
#include <ostream>
#include <iomanip>
#include <cstring>
#include <sstream>
#include <cassert>
#include <cstdlib>
#include <istream>
#include <fstream>
#include <climits>
#include <complex>
#include <memory>
#include <string>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef complex <ld> cd;

const bool db = false;

#define fs first
#define sd second
#define mp make_pair
#define pb push_back
#define ppb pop_back

#define inf 1000000007
#define nmax 100100
#define mmax 100100
#define eps 1e-12

unordered_set<int> answer;

int number_of_segments, need;

pair<int, int> segments[nmax];

bool check(int len) {
	unordered_set<int> cur_seg;
	vector<pair<int, pair<int, int > > > events;
	for (int id = 1; id <= number_of_segments; id++) {
		if (segments[id].second - segments[id].first + 1 >= len)
			events.push_back({ segments[id].first,{-1,id } }), events.push_back({ segments[id].second - len + 1,{1,id } });
	}
	sort(events.begin(), events.end());
	int balance = 0;
	for (int id = 0; id < (int)events.size(); id++) {
		if (events[id].second.first < 0)
			balance++, cur_seg.insert(events[id].second.second);
		else balance--, cur_seg.erase(events[id].second.second);
		if (balance >= need) {
			answer = cur_seg;
			return true;
		}
	}
	return false;
}

int main() {
#ifdef Ahoma
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif // Ahoma
	ios::sync_with_stdio(0);
	cin >> number_of_segments >> need;
	for (int id = 1; id <= number_of_segments; id++)
		cin >> segments[id].first >> segments[id].second;
	int left_side = 0, right_side = inf, mid;
	while (left_side + 1 != right_side) {
		mid = (left_side + right_side) >> 1;
		if (check(mid))
			left_side = mid;
		else right_side = mid;
	}
	if (check(right_side)) {
		cout << right_side << '\n';
		for (auto elem : answer)
			cout << elem << ' ';
	}
	else if (check(left_side)) {
		cout << left_side << '\n';
		for (auto elem : answer)
			cout << elem << ' ';
	}
	else {
		cout << "0\n";
		for (int id = 1; id <= need; id++)
			cout << id << ' ';
	}
	return 0;
}


#pragma comment(linker, "/STACK:100000000")
#define _SCL_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include <algorithm>
#include <memory.h>
#include <iostream>
#include <iterator>
#include <ostream>
#include <iomanip>
#include <cstring>
#include <sstream>
#include <cassert>
#include <cstdlib>
#include <istream>
#include <fstream>
#include <climits>
#include <complex>
#include <memory>
#include <string>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef complex <ld> cd;

const bool db = false;

#define fs first
#define sd second
#define mp make_pair
#define pb push_back
#define ppb pop_back

#define inf 1000000007
#define nmax 100100
#define mmax 100100
#define eps 1e-12

unordered_set<int> answer;

int number_of_segments, need;

pair<int, int> segments[nmax];

bool check(int len) {
	unordered_set<int> cur_seg;
	vector<pair<int, pair<int, int > > > events;
	for (int id = 1; id <= number_of_segments; id++) {
		if (segments[id].second - segments[id].first + 1 >= len)
			events.push_back({ segments[id].first,{-1,id } }), events.push_back({ segments[id].second - len + 1,{1,id } });
	}
	sort(events.begin(), events.end());
	int balance = 0;
	for (int id = 0; id < (int)events.size(); id++) {
		if (events[id].second.first < 0)
			balance++, cur_seg.insert(events[id].second.second);
		else balance--, cur_seg.erase(events[id].second.second);
		if (balance >= need) {
			answer = cur_seg;
			return true;
		}
	}
	return false;
}

string bad_answer;

int main() {
#ifdef Ahoma
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif // Ahoma
	ios::sync_with_stdio(0);
	cin >> number_of_segments >> need;
	bad_answer += "0\n";
	for (int id = 1; id <= need; id++)
		bad_answer += to_string(id) + " ";
	for (int id = 1; id <= number_of_segments; id++)
		cin >> segments[id].first >> segments[id].second;
	int left_side = 0, right_side = INT_MAX, mid;
	while (left_side + 1 != right_side) {
		mid = (left_side + right_side) >> 1;
		if (check(mid))
			left_side = mid;
		else right_side = mid;
	}
	if (check(right_side)) {
		cout << right_side << '\n';
		for (auto elem : answer)
			cout << elem << ' ';
	}
	else if (check(left_side)) {
		cout << left_side << '\n';
		for (auto elem : answer)
			cout << elem << ' ';
	}
	else cout << bad_answer;
	return 0;
}


#pragma comment(linker, "/STACK:100000000")
#define _SCL_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include <algorithm>
#include <memory.h>
#include <iostream>
#include <iterator>
#include <ostream>
#include <iomanip>
#include <cstring>
#include <sstream>
#include <cassert>
#include <cstdlib>
#include <istream>
#include <fstream>
#include <climits>
#include <complex>
#include <memory>
#include <string>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef complex <ld> cd;

const bool db = false;

#define fs first
#define sd second
#define mp make_pair
#define pb push_back
#define ppb pop_back

#define inf 1000000007
#define nmax 100100
#define mmax 100100
#define eps 1e-12

unordered_set<int> answer;

pair<int, int> segments[nmax];

unordered_set<int> cur_seg;
vector<pair<int, pair<int, int > > > events;
int balance = 0;

bool check(int len,const int &number_of_segments, const int &need) {
	cur_seg.clear();
	events.clear();
	for (int id = 1; id <= number_of_segments; id++) {
		if (segments[id].second - segments[id].first + 1 >= len)
			events.push_back({ segments[id].first,{-1,id } }), events.push_back({ segments[id].second - len + 1,{1,id } });
	}
	balance = 0;
	sort(events.begin(), events.end());
	for (int id = 0; id < (int)events.size(); id++) {
		if (events[id].second.first < 0)
			balance++, cur_seg.insert(events[id].second.second);
		else balance--, cur_seg.erase(events[id].second.second);
		if (balance >= need) {
			answer = cur_seg;
			return true;
		}
	}
	return false;
}

string bad_answer;

int main() {
#ifdef Ahoma
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif // Ahoma
	ios::sync_with_stdio(0);
	int number_of_segments, need;
	cin >> number_of_segments >> need;
	for (int id = 1; id <= number_of_segments; id++)
		cin >> segments[id].first >> segments[id].second;
	int left_side = 0, right_side = 2*inf, mid;
	while (left_side + 1 != right_side) {
		mid = (left_side + right_side) >> 1;
		if (check(mid,number_of_segments,need))
			left_side = mid;
		else right_side = mid;
	}
	if (check(right_side)) {
		cout << right_side << '\n';
		for (auto elem : answer)
			cout << elem << ' ';
	}
	else if (check(left_side)) {
		cout << left_side << '\n';
		for (auto elem : answer)
			cout << elem << ' ';
	}
	else {
		bad_answer += "0\n";
		for (int ident = 1; ident <= need; ident++)
			bad_answer += to_string(ident) + " ";
		cout << bad_answer;
	}
	return 0;
}


#pragma comment(linker, "/STACK:100000000")
#define _SCL_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include <algorithm>
#include <memory.h>
#include <iostream>
#include <iterator>
#include <ostream>
#include <iomanip>
#include <cstring>
#include <sstream>
#include <cassert>
#include <cstdlib>
#include <istream>
#include <fstream>
#include <climits>
#include <complex>
#include <memory>
#include <string>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef complex <ld> cd;

const bool db = false;

#define fs first
#define sd second
#define mp make_pair
#define pb push_back
#define ppb pop_back

#define inf 1000000007
#define nmax 100100
#define mmax 100100
#define eps 1e-12

unordered_set<int> answer;

int number_of_segments, need;

pair<int, int> segments[nmax];

unordered_set<int> cur_seg;
vector<pair<int, pair<int, int > > > events;
int balance = 0;

bool check(int len, bool ans=false) {
	if (ans)
		cur_seg.clear();
	events.clear();
	for (int id = 1; id <= number_of_segments; id++) {
		if (segments[id].second - segments[id].first + 1 >= len)
			events.push_back({ segments[id].first,{ -1,id } }), events.push_back({ segments[id].second - len + 1,{ 1,id } });
	}
	balance = 0;
	sort(events.begin(), events.end());
	for (int id = 0; id < (int)events.size(); id++) {
		if (events[id].second.first < 0) {
			balance++;
			if (ans)
				cur_seg.insert(events[id].second.second);
		}
		else {
			balance--;
			if (ans)
				cur_seg.erase(events[id].second.second);
		}
		if (balance >= need) {
			if (ans)
				answer = cur_seg;
			return true;
		}
	}
	return false;
}

string bad_answer;

int main() {
#ifdef Ahoma
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif // Ahoma
	ios::sync_with_stdio(0);
	cin >> number_of_segments >> need;
	int wtf_with_need = need;
	for (int id = 1; id <= number_of_segments; id++)
		cin >> segments[id].first >> segments[id].second;
	int left_side = 0, right_side = 2 * inf, mid;
	while (left_side + 1 != right_side) {
		mid = (left_side + right_side) >> 1;
		if (check(mid))
			left_side = mid;
		else right_side = mid;
	}
	check(left_side, true);
	cout << left_side << '\n';
	if (!left_side)
		for (int id = 1; id <= wtf_with_need; id++)
			answer.insert(id);
	for (auto elem : answer)
		cout << elem << ' ';
	return 0;
}


#pragma comment(linker, "/STACK:100000000")
#define _SCL_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#pragma GCC optimize ("O2")
#define _USE_MATH_DEFINES
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include <algorithm>
#include <memory.h>
#include <iostream>
#include <iterator>
#include <ostream>
#include <iomanip>
#include <cstring>
#include <sstream>
#include <cassert>
#include <cstdlib>
#include <istream>
#include <fstream>
#include <climits>
#include <complex>
#include <memory>
#include <string>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef complex <ld> cd;

const bool db = false;

#define fs first
#define sd second
#define mp make_pair
#define pb push_back
#define ppb pop_back

#define inf 1000000007
#define nmax 100100
#define mmax 100100
#define eps 1e-12

unordered_set<int> answer;

int number_of_segments, need;

pair<int, int> segments[nmax];

int balance = 0;

int nextInt() {
	int x = 0, p = 1;
	char c;
	do {
		c = getchar();
	} while (c <= 32);
	if (c == '-') {
		p = -1;
		c = getchar();
	}
	while (c >= '0' && c <= '9') {
		x = x * 10 + c - '0';
		c = getchar();
	}
	return x * p;
}

inline bool check(const int &len,const bool &ans=false) {
	if (ans)
		answer.clear();
	static vector<pair<int, pair<int, int > > > events;
	events.resize(0);
	for (int id = 1; id <= number_of_segments; id++) {
		if (segments[id].second - segments[id].first + 1 >= len) {
			events.push_back({ segments[id].first,{ -1,id } });
			events.push_back({ segments[id].second - len + 1,{ 1,id } });
		}
	}
	balance = 0;
	sort(events.begin(), events.end());
	for (int id = 0; id < (int)events.size(); id++) {
		if (events[id].second.first < 0) {
			balance++;
			if (ans)
				answer.insert(events[id].second.second);
		}
		else {
			balance--;
			if (ans)
				answer.erase(events[id].second.second);
		}
		if (balance == need)
			return true;
	}
	return false;
}

int main() {
#ifdef Ahoma
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif // Ahoma
	number_of_segments = nextInt();
	need = nextInt();
	int wtf_with_need = need;
	int left_side = 0, right_side = 0, mid;
	for (int id = 1; id <= number_of_segments; id++) {
		segments[id].first = nextInt(), segments[id].second = nextInt();
		right_side = max(right_side, segments[id].second - segments[id].first + 5);
	}
	while (left_side + 1 != right_side) {
		mid = (left_side + right_side) >> 1;
		if (check(mid))
			left_side = mid;
		else right_side = mid;
	}
	check(left_side, true);
	printf("%d\n", left_side);
	if (!left_side)
		for (int id = 1; id <= wtf_with_need; id++)
			answer.insert(id);
	for (auto elem : answer)
		printf("%d ", elem);
	return 0;
}


#pragma comment(linker, "/STACK:100000000")
#define _SCL_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include <algorithm>
#include <memory.h>
#include <iostream>
#include <iterator>
#include <ostream>
#include <iomanip>
#include <cstring>
#include <sstream>
#include <cassert>
#include <cstdlib>
#include <istream>
#include <fstream>
#include <climits>
#include <complex>
#include <memory>
#include <string>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef complex <ld> cd;

const bool db = false;

#define fs first
#define sd second
#define mp make_pair
#define pb push_back
#define ppb pop_back

#define inf 1000000007
#define nmax 100100
#define mmax 100100
#define eps 1e-12

unordered_set<int> answer;

int number_of_segments, need;

pair<int, int> segments[nmax];

unordered_set<int> cur_seg;
vector<pair<int, pair<int, int > > > events;
int balance = 0;

bool check(int len) {
	cur_seg.clear();
	events.clear();
	for (int id = 1; id <= number_of_segments; id++) {
		if (segments[id].second - segments[id].first + 1 >= len)
			events.push_back({ segments[id].first,{-1,id } }), events.push_back({ segments[id].second - len + 1,{1,id } });
	}
	balance = 0;
	sort(events.begin(), events.end());
	for (int id = 0; id < (int)events.size(); id++) {
		if (events[id].second.first < 0)
			balance++, cur_seg.insert(events[id].second.second);
		else balance--, cur_seg.erase(events[id].second.second);
		if (balance >= need) {
			answer = cur_seg;
			return true;
		}
	}
	return false;
}

string bad_answer;

int main() {
#ifdef Ahoma
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif // Ahoma
	ios::sync_with_stdio(0);
	cin >> number_of_segments >> need;
	for (int id = 1; id <= number_of_segments; id++)
		cin >> segments[id].first >> segments[id].second;
	int left_side = 0, right_side = 2*inf, mid;
	while (left_side + 1 != right_side) {
		mid = (left_side + right_side) >> 1;
		if (check(mid))
			left_side = mid;
		else right_side = mid;
	}
	if (check(right_side)) {
		cout << right_side << '\n';
		for (auto elem : answer)
			cout << elem << ' ';
	}
	else if (check(left_side)) {
		cout << left_side << '\n';
		for (auto elem : answer)
			cout << elem << ' ';
	}
	else {
		bad_answer += "0\n";
		for (int id = 1; id <= need; id++)
			bad_answer += to_string(id) + " ";
		cout << bad_answer;
	}
	return 0;
}


#pragma comment(linker, "/STACK:100000000")
#define _SCL_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#pragma GCC optimize ("O2")
#define _USE_MATH_DEFINES
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include <algorithm>
#include <memory.h>
#include <iostream>
#include <iterator>
#include <ostream>
#include <iomanip>
#include <cstring>
#include <sstream>
#include <cassert>
#include <cstdlib>
#include <istream>
#include <fstream>
#include <climits>
#include <complex>
#include <memory>
#include <string>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef complex <ld> cd;

const bool db = false;

#define fs first
#define sd second
#define mp make_pair
#define pb push_back
#define ppb pop_back

#define inf 1000000007
#define nmax 100100
#define mmax 100100
#define eps 1e-12

unordered_set<int> answer;

int number_of_segments, need;

pair<int, int> segments[nmax];

int balance = 0;

int nextInt() {
	int x = 0, p = 1;
	char c;
	do {
		c = getchar();
	} while (c <= 32);
	if (c == '-') {
		p = -1;
		c = getchar();
	}
	while (c >= '0' && c <= '9') {
		x = x * 10 + c - '0';
		c = getchar();
	}
	return x * p;
}

inline bool check(const int &len,const bool &ans=false) {
	if (ans)
		answer.clear();
	static vector<pair<int, pair<int, int > > > events;
	for (int id = 1; id <= number_of_segments; id++) {
		if (segments[id].second - segments[id].first + 1 >= len) {
			events.push_back({ segments[id].first,{ -1,id } });
			events.push_back({ segments[id].second - len + 1,{ 1,id } });
		}
	}
	balance = 0;
	sort(events.begin(), events.end());
	for (int id = 0; id < (int)events.size(); id++) {
		if (events[id].second.first < 0) {
			balance++;
			if (ans)
				answer.insert(events[id].second.second);
		}
		else {
			balance--;
			if (ans)
				answer.erase(events[id].second.second);
		}
		if (balance == need)
			return true;
	}
	return false;
}

int main() {
#ifdef Ahoma
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif // Ahoma
	number_of_segments = nextInt();
	need = nextInt();
	int wtf_with_need = need;
	int left_side = 0, right_side = 0, mid;
	for (int id = 1; id <= number_of_segments; id++) {
		segments[id].first = nextInt(), segments[id].second = nextInt();
		right_side = max(right_side, segments[id].second - segments[id].first + 5);
	}
	while (left_side + 1 != right_side) {
		mid = (left_side + right_side) >> 1;
		if (check(mid))
			left_side = mid;
		else right_side = mid;
	}
	check(left_side, true);
	printf("%d\n", left_side);
	if (!left_side)
		for (int id = 1; id <= wtf_with_need; id++)
			answer.insert(id);
	for (auto elem : answer)
		printf("%d ", elem);
	return 0;
}


#pragma comment(linker, "/STACK:100000000")
#define _SCL_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include <algorithm>
#include <memory.h>
#include <iostream>
#include <iterator>
#include <ostream>
#include <iomanip>
#include <cstring>
#include <sstream>
#include <cassert>
#include <cstdlib>
#include <istream>
#include <fstream>
#include <climits>
#include <complex>
#include <memory>
#include <string>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef complex <ld> cd;

const bool db = false;

#define fs first
#define sd second
#define mp make_pair
#define pb push_back
#define ppb pop_back

#define inf 1000000007
#define nmax 100100
#define mmax 100100
#define eps 1e-12

unordered_set<int> answer;

int number_of_segments, need;

pair<int, int> segments[nmax];

vector<pair<int, pair<int, int > > > events;
int balance = 0;

inline bool check(const int &len,const bool &ans=false) {
	if (ans)
		answer.clear();
	events.clear();
	for (int id = 1; id <= number_of_segments; id++) {
		if (segments[id].second - segments[id].first + 1 >= len)
			events.push_back({ segments[id].first,{ -1,id } }), events.push_back({ segments[id].second - len + 1,{ 1,id } });
	}
	balance = 0;
	sort(events.begin(), events.end());
	for (int id = 0; id < (int)events.size(); id++) {
		if (events[id].second.first < 0) {
			balance++;
			if (ans)
				answer.insert(events[id].second.second);
		}
		else {
			balance--;
			if (ans)
				answer.erase(events[id].second.second);
		}
		if (balance == need)
			return true;
	}
	return false;
}

int main() {
#ifdef Ahoma
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif // Ahoma
	ios::sync_with_stdio(0);
	scanf("%d %d\n", &number_of_segments, &need);
	int wtf_with_need = need;
	for (int id = 1; id <= number_of_segments; id++)
		scanf("%d %d\n", &segments[id].first, &segments[id].second);
	int left_side = 0, right_side = 2 * inf, mid;
	while (left_side + 1 != right_side) {
		mid = (left_side + right_side) >> 1;
		if (check(mid))
			left_side = mid;
		else right_side = mid;
	}
	check(left_side, true);
	printf("%d\n", left_side);
	if (!left_side)
		for (int id = 1; id <= wtf_with_need; id++)
			answer.insert(id);
	for (auto elem : answer)
		printf("%d ", elem);
	return 0;
}


#pragma comment(linker, "/STACK:100000000")
#define _SCL_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include <algorithm>
#include <memory.h>
#include <iostream>
#include <iterator>
#include <ostream>
#include <iomanip>
#include <cstring>
#include <sstream>
#include <cassert>
#include <cstdlib>
#include <istream>
#include <fstream>
#include <climits>
#include <complex>
#include <memory>
#include <string>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef complex <ld> cd;

const bool db = false;

#define fs first
#define sd second
#define mp make_pair
#define pb push_back
#define ppb pop_back

#define inf 1000000007
#define nmax 100100
#define mmax 100100
#define eps 1e-12

unordered_set<int> answer;

int number_of_segments, need;

pair<int, int> segments[nmax];

bool check(int len) {
	unordered_set<int> cur_seg;
	vector<pair<int, pair<int, int > > > events;
	for (int id = 1; id <= number_of_segments; id++) {
		if (segments[id].second - segments[id].first + 1 >= len)
			events.push_back({ segments[id].first,{-1,id } }), events.push_back({ segments[id].second - len + 1,{1,id } });
	}
	sort(events.begin(), events.end());
	int balance = 0;
	for (int id = 0; id < (int)events.size(); id++) {
		if (events[id].second.first < 0)
			balance++, cur_seg.insert(events[id].second.second);
		else balance--, cur_seg.erase(events[id].second.second);
		if (balance >= need) {
			answer = cur_seg;
			return true;
		}
	}
	return false;
}

string bad_answer;

int main() {
#ifdef Ahoma
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif // Ahoma
	ios::sync_with_stdio(0);
	cin >> number_of_segments >> need;
	bad_answer += "0\n";
	for (int id = 1; id <= need; id++)
		bad_answer += to_string(id) + " ";
	for (int id = 1; id <= number_of_segments; id++)
		cin >> segments[id].first >> segments[id].second;
	int left_side = 0, right_side = 2*inf, mid;
	while (left_side + 1 != right_side) {
		mid = (left_side + right_side) >> 1;
		if (check(mid))
			left_side = mid;
		else right_side = mid;
	}
	if (check(right_side)) {
		cout << right_side << '\n';
		for (auto elem : answer)
			cout << elem << ' ';
	}
	else if (check(left_side)) {
		cout << left_side << '\n';
		for (auto elem : answer)
			cout << elem << ' ';
	}
	else cout << bad_answer;
	return 0;
}


#pragma comment(linker, "/STACK:100000000")
#define _SCL_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include <algorithm>
#include <memory.h>
#include <iostream>
#include <iterator>
#include <ostream>
#include <iomanip>
#include <cstring>
#include <sstream>
#include <cassert>
#include <cstdlib>
#include <istream>
#include <fstream>
#include <climits>
#include <complex>
#include <memory>
#include <string>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef complex <ld> cd;

const bool db = false;

#define fs first
#define sd second
#define mp make_pair
#define pb push_back
#define ppb pop_back

#define inf 1000000007
#define nmax 100100
#define mmax 100100
#define eps 1e-12

unordered_set<int> answer;

int number_of_segments, need;

pair<int, int> segments[nmax];

vector<pair<int, pair<int, int > > > events;
int balance = 0;

inline bool check(const int &len,const bool &ans=false) {
	if (ans)
		answer.clear();
	events.clear();
	for (int id = 1; id <= number_of_segments; id++) {
		if (segments[id].second - segments[id].first + 1 >= len)
			events.push_back({ segments[id].first,{ -1,id } }), events.push_back({ segments[id].second - len + 1,{ 1,id } });
	}
	balance = 0;
	sort(events.begin(), events.end());
	for (int id = 0; id < (int)events.size(); id++) {
		if (events[id].second.first < 0) {
			balance++;
			if (ans)
				answer.insert(events[id].second.second);
		}
		else {
			balance--;
			if (ans)
				answer.erase(events[id].second.second);
		}
		if (balance == need)
			return true;
	}
	return false;
}

int main() {
#ifdef Ahoma
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif // Ahoma
	scanf("%d %d\n", &number_of_segments, &need);
	int wtf_with_need = need;
	for (int id = 1; id <= number_of_segments; id++)
		scanf("%d %d\n", &segments[id].first, &segments[id].second);
	int left_side = 0, right_side = 2 * inf, mid;
	while (left_side + 1 != right_side) {
		mid = (left_side + right_side) >> 1;
		if (check(mid))
			left_side = mid;
		else right_side = mid;
	}
	check(left_side, true);
	printf("%d\n", left_side);
	if (!left_side)
		for (int id = 1; id <= wtf_with_need; id++)
			answer.insert(id);
	for (auto elem : answer)
		printf("%d ", elem);
	return 0;
}


#pragma comment(linker, "/STACK:100000000")
#define _SCL_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include <algorithm>
#include <memory.h>
#include <iostream>
#include <iterator>
#include <ostream>
#include <iomanip>
#include <cstring>
#include <sstream>
#include <cassert>
#include <cstdlib>
#include <istream>
#include <fstream>
#include <climits>
#include <complex>
#include <memory>
#include <string>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef complex <ld> cd;

const bool db = false;

#define fs first
#define sd second
#define mp make_pair
#define pb push_back
#define ppb pop_back

#define inf 1000000007
#define nmax 100100
#define mmax 100100
#define eps 1e-12

unordered_set<int> answer;

int number_of_segments, need;

pair<int, int> segments[nmax];

unordered_set<int> cur_seg;
vector<pair<int, pair<int, int > > > events;
int balance = 0;

bool check(int len) {
	cur_seg.clear();
	events.clear();
	for (int id = 1; id <= number_of_segments; id++) {
		if (segments[id].second - segments[id].first + 1 >= len)
			events.push_back({ segments[id].first,{-1,id } }), events.push_back({ segments[id].second - len + 1,{1,id } });
	}
	balance = 0;
	sort(events.begin(), events.end());
	for (int id = 0; id < (int)events.size(); id++) {
		if (events[id].second.first < 0)
			balance++, cur_seg.insert(events[id].second.second);
		else balance--, cur_seg.erase(events[id].second.second);
		if (balance >= need) {
			answer = cur_seg;
			return true;
		}
	}
	return false;
}

string bad_answer;

int main() {
#ifdef Ahoma
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif // Ahoma
	ios::sync_with_stdio(0);
	cin >> number_of_segments >> need;
	for (int id = 1; id <= number_of_segments; id++)
		cin >> segments[id].first >> segments[id].second;
	int left_side = 0, right_side = 2*inf, mid;
	while (left_side + 1 != right_side) {
		mid = (left_side + right_side) >> 1;
		if (check(mid))
			left_side = mid;
		else right_side = mid;
	}
	if (check(right_side)) {
		cout << right_side << '\n';
		for (auto elem : answer)
			cout << elem << ' ';
	}
	else if (check(left_side)) {
		cout << left_side << '\n';
		for (auto elem : answer)
			cout << elem << ' ';
	}
	else {
		bad_answer += "0\n";
		for (int ident = 1; ident <= need; ident++)
			bad_answer += to_string(ident) + " ";
		cout << bad_answer;
	}
	return 0;
}


#pragma comment(linker, "/STACK:100000000")
#define _SCL_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#pragma GCC ostarimize("O500")
#define _USE_MATH_DEFINES
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include <algorithm>
#include <memory.h>
#include <iostream>
#include <iterator>
#include <ostream>
#include <iomanip>
#include <cstring>
#include <sstream>
#include <cassert>
#include <cstdlib>
#include <istream>
#include <fstream>
#include <climits>
#include <complex>
#include <memory>
#include <string>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef complex <ld> cd;

const bool db = false;

#define fs first
#define sd second
#define mp make_pair
#define pb push_back
#define ppb pop_back

#define inf 1000000007
#define nmax 100100
#define mmax 100100
#define eps 1e-12

unordered_set<int> answer;

int number_of_segments, need;

pair<int, int> segments[nmax];

bool check(int len) {
	unordered_set<int> cur_seg;
	vector<pair<int, pair<int, int > > > events;
	for (int id = 1; id <= number_of_segments; id++) {
		if (segments[id].second - segments[id].first + 1 >= len)
			events.push_back({ segments[id].first,{-1,id } }), events.push_back({ segments[id].second - len + 1,{1,id } });
	}
	sort(events.begin(), events.end());
	int balance = 0;
	for (int id = 0; id < (int)events.size(); id++) {
		if (events[id].second.first < 0)
			balance++, cur_seg.insert(events[id].second.second);
		else balance--, cur_seg.erase(events[id].second.second);
		if (balance >= need) {
			answer = cur_seg;
			return true;
		}
	}
	return false;
}

int main() {
#ifdef Ahoma
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif // Ahoma
	ios::sync_with_stdio(0);
	cin >> number_of_segments >> need;
	for (int id = 1; id <= number_of_segments; id++)
		cin >> segments[id].first >> segments[id].second;
	int left_side = 0, right_side = inf, mid;
	while (left_side + 1 != right_side) {
		mid = (left_side + right_side) >> 1;
		if (check(mid))
			left_side = mid;
		else right_side = mid;
	}
	if (check(right_side)) {
		cout << right_side << '\n';
		for (auto elem : answer)
			cout << elem << ' ';
	}
	else if (check(left_side)) {
		cout << left_side << '\n';
		for (auto elem : answer)
			cout << elem << ' ';
	}
	else {
		puts("0");
		for (int id = 1; id <= need; id++)
			cout << id << ' ';
	}
	return 0;
}


#pragma comment(linker, "/STACK:100000000")
#define _SCL_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include <algorithm>
#include <memory.h>
#include <iostream>
#include <iterator>
#include <ostream>
#include <iomanip>
#include <cstring>
#include <sstream>
#include <cassert>
#include <cstdlib>
#include <istream>
#include <fstream>
#include <climits>
#include <complex>
#include <memory>
#include <string>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef complex <ld> cd;

const bool db = false;

#define fs first
#define sd second
#define mp make_pair
#define pb push_back
#define ppb pop_back

#define inf 1000000007
#define nmax 100100
#define mmax 100100
#define eps 1e-12

unordered_set<int> answer;

int number_of_segments, need;

pair<int, int> segments[nmax];

vector<pair<int, pair<int, int > > > events;
int balance = 0;

inline bool check(const int &len,const bool &ans=false) {
	if (ans)
		answer.clear();
	events.clear();
	for (int id = 1; id <= number_of_segments; id++) {
		if (segments[id].second - segments[id].first + 1 >= len)
			events.push_back({ segments[id].first,{ -1,id } }), events.push_back({ segments[id].second - len + 1,{ 1,id } });
	}
	balance = 0;
	sort(events.begin(), events.end());
	for (int id = 0; id < (int)events.size(); id++) {
		if (events[id].second.first < 0) {
			balance++;
			if (ans)
				answer.insert(events[id].second.second);
		}
		else {
			balance--;
			if (ans)
				answer.erase(events[id].second.second);
		}
		if (balance == need)
			return true;
	}
	return false;
}

int main() {
#ifdef Ahoma
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif // Ahoma
	ios::sync_with_stdio(0);
	cin >> number_of_segments >> need;
	int wtf_with_need = need;
	for (int id = 1; id <= number_of_segments; id++)
		cin >> segments[id].first >> segments[id].second;
	int left_side = 0, right_side = 2 * inf, mid;
	while (left_side + 1 != right_side) {
		mid = (left_side + right_side) >> 1;
		if (check(mid))
			left_side = mid;
		else right_side = mid;
	}
	check(left_side, true);
	cout << left_side << '\n';
	if (!left_side)
		for (int id = 1; id <= wtf_with_need; id++)
			answer.insert(id);
	for (auto elem : answer)
		cout << elem << ' ';
	return 0;
}


#pragma comment(linker, "/STACK:100000000")
#define _SCL_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#pragma GCC ostarimize("O500")
#define _USE_MATH_DEFINES
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include <algorithm>
#include <memory.h>
#include <iostream>
#include <iterator>
#include <ostream>
#include <iomanip>
#include <cstring>
#include <sstream>
#include <cassert>
#include <cstdlib>
#include <istream>
#include <fstream>
#include <climits>
#include <complex>
#include <memory>
#include <string>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef complex <ld> cd;

const bool db = false;

#define fs first
#define sd second
#define mp make_pair
#define pb push_back
#define ppb pop_back

#define inf 1000000007
#define nmax 300100
#define mmax 100100
#define eps 1e-12

pair<int, int> Points_pair[nmax];

int main()
{
#ifdef Ahoma
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
	ios::sync_with_stdio(0);
	int Number, Count;
	cin >> Number >> Count;
	int Left, Right;
	vector<pair<int, int> > Points;
	for (int Row = 1; Row <= Number; Row++)
	{
		cin >> Left >> Right;
		Points_pair[Row] = { Left,Right };
		Points.push_back({ Left,-Row });
		Points.push_back({ Right,Row });
	}
	sort(Points.begin(), Points.end());
	int Max_Ans = 0;
	set<int> current, answer_points;
	set<pair<int, int> > max_left, min_right;
	for (int Row = 0; Row < 2 * Number; Row++)
	{
		if (Points[Row].second < 0)
		{
			current.insert(-Points[Row].second);
			max_left.insert({ -Points[Row].first,-Points[Row].second });
			min_right.insert({ Points_pair[-Points[Row].second].second,-Points[Row].second });
		}
		if (Points[Row].second > 0)
		{
			current.erase(Points[Row].second);
			max_left.erase(max_left.find({ -Points_pair[Points[Row].second].first,Points[Row].second }));
			min_right.erase(min_right.find({Points[Row].first, Points[Row].second}));
		}
		if (current.size() >= Count)
		{
			Left = -(*max_left.begin()).first;
			Right = (*min_right.begin()).first;
			if (Right - Left + 1 > Max_Ans)
			{
				Max_Ans = Right - Left + 1;
				answer_points = { (*max_left.begin()).second,(*min_right.begin()).second };
				for (auto Pnt : current)
				{
					answer_points.insert(Pnt);
					if (answer_points.size() == Count)
						break;
				}
			}
		}
	}
	if (!Max_Ans && !answer_points.size())
		for (int Row = 1; Row <= Count; Row++)
			answer_points.insert(Row);
	cout << Max_Ans << '\n';
	for (auto Num : answer_points)
		cout << Num << ' ';
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int nextInt() {
	int x = 0, p = 1;
	char c;
	do {
		c = getchar();
	} while (c <= 32);
	if (c == '-') {
		p = -1;
		c = getchar();
	}
	while (c >= '0' && c <= '9') {
		x = x * 10 + c - '0';
		c = getchar();
	}
	return x * p;
}

#define all(x) (x).begin(), (x).end()

const int N = (int)3e5 + 5;
const int MAX_VAL = (int)1e9;

int n;
ll l[N], r[N];

struct event {
	ll x;
	int c;
	event() {}
	event(ll x, int c) : x(x), c(c) {}
};

pair<ll, int> check(ll len) {
	if (len == 0) return make_pair(0LL, n);
	static vector<event> evs;
	evs.resize(0);
	for (int i = 1; i <= n; i++) {
		if (r[i] - len > l[i]) {
			evs.push_back(event(l[i], 1));
			evs.push_back(event(r[i] - len, -1));
		}
	}
	sort(all(evs), [](const event & a, const event & b) { return a.x < b.x; });
	reverse(all(evs));
	int cnt = 0, maxiCnt = 0;
	ll bestPos = 0;
	while (evs.size() > 0) {
		ll x = evs.back().x;
		while (evs.size() > 0 && evs.back().x == x) {
			cnt += evs.back().c;
			evs.pop_back();
		}
		if (cnt > maxiCnt) {
			maxiCnt = cnt;
			bestPos = x;
		}
	}
	return make_pair(bestPos, maxiCnt);
}

vector<int> getAns(ll len) {
	if (len == 0) {
		vector<int> res(n);
		iota(all(res), 1);
		return res;
	}
	ll pos = check(len).first;
	vector<int> res;
	for (int i = 1; i <= n; i++) {
		if (pos >= l[i] && pos < r[i] - len) {
			res.push_back(i);
		}
	}
	return res;
}

int main() {
	n = nextInt();
	int k = nextInt();
	for (int i = 1; i <= n; i++) {
		l[i] = nextInt();
		r[i] = nextInt() + 2;
	}
	ll l = 0, r = MAX_VAL + MAX_VAL + 5;
	while (r - l > 1) {
		ll mid = (l + r) >> 1;
		if (check(mid).second >= k) l = mid;
		else r = mid;
	}

	vector<int> ans = getAns(l);

	cout << l << endl;
	assert((int)ans.size() >= k);
	ans.resize(k);
	for (int i : ans) {
		printf("%d ", i);
	}
	puts("");
}


#include<bits/stdc++.h>
#define ll long long
#define INF 1000000001
using namespace std;

int l[1000007],r[1000007],lt[100007],rt[100007];

static int mark[1000007];
int jstGreater(int a[],int n,int x)
{
	int beg,last,mid;
	beg=0;last=n-1;
	if(a[n-1]<=x)
	return n;
	while(beg<=last)
	{
		mid=(beg+last)/2;
		if((mid==0 || a[mid-1]<=x) && a[mid]>x)
		return mid;
		else if((mid+1==n || a[mid+1]>x) && a[mid]<=x)
		return mid+1;
		else if(a[mid]<=x)
		beg=mid+1;
		else last=mid-1;
	}
	return n;
}

struct node{
	int first,second,idx;
	node(){}
	node(int a,int b,int c){
		first = a;second = b;idx = c;
	}
}arr[1000007];

struct node2{
    int val,idx;
    node2(){}
    node2(int a,int b){
        val =a;idx = b;
    }
}sl[1000007],sr[1000007];

bool compare2(node2 l,node2 r){
    return l.val < r.val;
}
/*
int getSum(unordered_map<int,int> &BITree, int index)
{
    int sum = 0; // Iniialize result

    // index in BITree[] is 1 more than the index in arr[]
    index = index + 1;

    // Traverse ancestors of BITree[index]
    while (index>0)
    {
        // Add current element of BITree to sum
        sum += BITree[index];

        // Move index to parent node in getSum View
        index -= index & (-index);
    }
    return sum;
}

// Updates a node in Binary Index Tree (BITree) at given index
// in BITree.  The given value 'val' is added to BITree[i] and
// all of its ancestors in tree.
void updateBIT(unordered_map<int,int> &BITree, int n, int index, int val)
{
    // index in BITree[] is 1 more than the index in arr[]
    index = index + 1;

    // Traverse all ancestors and add 'val'
    while (index <= n)
    {
       // Add 'val' to current node of BI Tree
       BITree[index] += val;

       // Update index to that of parent in update View
       index += index & (-index);
    }
}
*/
bool check(int win,int n,int k){
	int i,v1,v2,zmin,zmax,top=0;
	/*
	cout<<"\ncheck for "<<win<<" "<<n<<"\n";
    for(i = 1 ; i <= n;i++)
	cout<<l[i]-INF<<" ";
	cout<<"\n";
	for(i = 1 ; i <= n;i++)
	cout<<r[i]-INF<<" ";
	cout<<"\n";
	*/

	for(i = 1 ; i <= n ;i++){
        if(r[i] - l[i] +1 >= win){
            top++;
            lt[top] = l[i];
            rt[top] = r[i];

        }
	}
	sort(lt+1,lt+top+1);
	sort(rt+1,rt+top+1);
	/*
	for(i = 1 ; i < top;i++)
	cout<<lt[i]-INF<<" ";
	cout<<"\n";
	for(i = 1 ; i < top;i++)
	cout<<rt[i]-INF<<" ";
	cout<<"\n";
	*/

	for(i = 1 ; i <= 2*n ;i++){
        if(r[arr[i].idx] - l[arr[i].idx] + 1 < win)
        continue;
		if(arr[i].second == 0){
			zmin = arr[i].first;
			zmax = arr[i].first + win-1;
		}
		else{
			zmax = arr[i].first;
			zmin = arr[i].first- win+1;
		}

		//v1 = getSum(BITStart,zmin);
		//v2 = getSum(BITEnd,zmax-1);
		v1 = jstGreater(lt+1,top,zmin);
		v2 = jstGreater(rt+1,top,zmax-1);
		//cout<<v1<<" "<<v2<<"\n";
		if(v1-v2 >= k)
			return 1;
	}
	return 0;
}

void getRes(int win,int n,int k){
	int i,v1,v2,zmin,zmax,j,cnt = 0,top=0;
	for(i = 1 ; i <= n ;i++){
        if(r[i] - l[i] +1 >= win){
            top++;
            lt[top] = l[i];
            rt[top] = r[i];
            sl[top] = node2(l[i],i);
            sr[top] = node2(r[i],i);

        }
	}
	sort(lt+1,lt+top+1);
	sort(rt+1,rt+top+1);
	sort(sl+1,sl+top+1,compare2);
	sort(sr+1,sr+top+1,compare2);
	/*
	for(i = 1 ; i < top;i++)
	cout<<lt[i]-INF<<" ";
	cout<<"\n";
	for(i = 1 ; i < top;i++)
	cout<<rt[i]-INF<<" ";
	cout<<"\n";
	*/

	for(i = 1 ; i <= 2*n ;i++){
        if(r[arr[i].idx] - l[arr[i].idx] + 1 < win)
        continue;
		if(arr[i].second == 0){
			zmin = arr[i].first;
			zmax = arr[i].first + win-1;
		}
		else{
			zmax = arr[i].first;
			zmin = arr[i].first- win+1;
		}

		v1 = jstGreater(lt+1,top,zmin);
		v2 = jstGreater(rt+1,top,zmax-1);

		if(v1-v2 >= k){
            for(j = 1 ; j <= v2;j++){
                mark[sr[j].idx]=1;
            }
            for(j = 1 ; j <= v1;j++){
                if(!mark[sl[j].idx]){
                    printf("%d ",sl[j].idx);
                    cnt++;
                    if(cnt == k)
                    break;
                }
            }
            printf("\n");
            return ;
		}
	}

}

bool compare(node l, node r){
    if(l.first == r.first)
    return l.second < r.second;
    return l.first < r.first;
}

int main(){
    //cout<<INT_MAX<<"\n";
	int n,k,i,beg,last,mid;
    scanf("%d%d",&n,&k);
	for(i = 1 ; i <= n ;i++){
		scanf("%d%d",&l[i],&r[i]);
		l[i]+=INF;
		r[i]+=INF;
    }
	for(i = 1 ; i <= n ;i++){
		arr[i] = node(l[i],0,i);
		arr[n+i] = node(r[i],1,i);
	}
	sort(arr+1,arr+2*n+1,compare);
	/*
	for(i = 1 ; i <= n ;i++){
		updateBIT(BITStart,2000000020LL,l[i],1);
		updateBIT(BITEnd,2000000020LL,r[i],1);
	}
	*/

	//cout<<check(32,n,k)<<"\n";

	/*
	cout<<"\n";
	for(i = 1 ; i <= 2*n ;i++)
	cout<<arr[i].first<<" "<<arr[i].second<<"   ";
	cout<<"\n";
	*/

	beg = 0;
	last = 2000000001;
	while(beg < last){
		mid = beg + (last+1-beg)/2;
		if(check(mid,n,k)){
			beg = mid;
		}
		else{
			last = mid-1;
		}
	}

	//cout<<getSum(BITStart,2)<<"\n";
	//cout<<getSum(BITStart,41)<<"\n";
	//cout<<check(31,n,k)<<"\n";
	//cout<<beg<<"\n";

	printf("%d\n",beg);

	if(beg == 0){
        for(i = 1 ; i <= k ;i++)
        printf("%d ",i);
        printf("\n");
	}
	else
	getRes(beg,n,k);

	return 0;
}