    #include<bits/stdc++.h>
    using namespace std;

    #define LOCAL 0

    #define length(a) (sizeof(a)/sizeof(a[0]))
    #define print(v,i,x) for(int j=i;j<=x;j++){cout<<v[j]<<" ";}cout<<endl;
    #define pb push_back
    #define mp make_pair
    #define lli long long int
    #define ulli unsigned long long int
    #define all(x) x.begin(),x.end()
    #define f first
    #define s second

    #define si(x) scanf("%d",&x);
    #define sli(x) scanf("%ld",&x);
    #define slli(x) scanf("%lld",&x);
    #define si2(x,y) {si(x);si(y);}
    #define si3(x,y,z) {si(x);si(y);si(z);}
    #define slli2(x,y) {slli(x);slli(y);}
    #define slli3(x,y,z) {slli(x);slli(y);slli(z);}

    #define pi(x) printf("%d",x);
    #define pi2(x,y) printf("%d %d",x,y);
    #define pi3(x,y,z) printf("%d %d %d",x,y,z);
    #define pli(x) printf("%ld",x);
    #define plli(x) printf("%lld",x);
    #define plli2(x,y) printf("%lld %lld",x,y);
    #define plli3(x,y,z) printf("%lld %lld %lld",x,y,z);
    #define pn printf("\n");
    #define ps printf(" ");
    #define pc(c) printf("%c",c);

    #define FOR(n) for(int i=0;i<n;i++)
    #define FORi(x,n) for(int i=x;i<=n;i++)
    #define FORj(x,n) for(int j=x;j<=n;j++)
    #define FORk(x,n) for(int k=x;k<=n;k++)
    #define ROFi(x,n) for(int i=x;i>=n;i--)
    #define ROFj(x,n) for(int j=x;j>=n;j--)
    #define ROFk(x,n) for(int k=x;k>=n;k--)

    #define debug(x) cout << "  - " << #x << ": " << x << endl;
    #define debugs(x, y) cout << "  - " << #x << ": " << x << "         " << #y << ": " << y << endl;
    #define debugss(x, y, z) cout << "  - " << #x << ": " << x << "         " << #y << ": " << y << "         " << #z << ": " << z <<  endl;
    #define fastIO 	std::ios::sync_with_stdio(false);cin.tie(NULL);

    typedef vector<int> vi;
    typedef vector<long> vli;
    typedef vector<long long> vlli;
    typedef vector<string> vstr;

    typedef pair<int,int> prii;
    typedef pair<int,lli> prilli;
    typedef pair<lli,int> prllii;
    typedef pair<lli,lli> prllilli;

    template <class T>T max3(T a,T b,T c){return max2(max2(a,b),c);}
    template <class T>T min3(T a,T b,T c){return min2(min2(a,b),c);}
    template <class T>T max4(T a,T b,T c,T d){return max2(max2(a,b),max2(c,d));}
    template <class T>T min4(T a,T b,T c,T d){return min2(min2(a,b),max2(c,d));}

    const lli mod = 1000000007ll;
    const lli MOD = 1000000009ll;
    const lli INF = LLONG_MAX/10;
    const int inf = INT_MAX/2;

    lli count_bit(lli _x){lli _ret=0;while(_x){if(_x%2==1)_ret++;_x/=2;}return _ret;}
    lli check_bit(lli _mask,lli _i){lli x=1;return (_mask&(x<<_i))==0?0:1;}
    lli set_bit(lli _mask,lli _i){lli x=1;_mask=_mask|(x<<_i);return _mask;}
    lli powermod(lli _a,lli _b,lli _m=mod){lli _r=1;while(_b){if(_b%2==1)_r=(_r*_a)%_m;_b/=2;_a=(_a*_a)%_m;}return _r;}
    lli power(lli _a,lli _b){lli _r=1;while(_b){if(_b%2==1)_r=(_r*_a);_b/=2;_a=(_a*_a);}return _r;}
    lli add(lli a,lli b,lli m=mod){lli x=a+b;while(x>=m)x-=m;return x;}
    lli sub(lli a,lli b,lli m=mod){lli x=a-b;while(x<0)x+=m;return x;}
    lli mul(lli a,lli b,lli m=mod){lli x=a*b;x%=m;return x;}
    lli gcd(lli a,lli b){ if(a<b) {a=a^b;b=a^b;a=a^b;} if(b==0)return a; lli t; while(b){t=b; b=a%b; a=t;}return a;}
    lli lcm(lli a,lli b){ return (a*b)/gcd(a,b); }

     vector<string> _split(const string& s, char c) {
        vector<string> v;
        stringstream ss(s);
        string x;
        while (getline(ss, x, c))
            v.emplace_back(x);
        return v;
    }

    //	int dx[]={-1,-1,0,1,1,1,0,-1};
    //	int dy[]={0,1,1,1,0,-1,-1,-1};

    //int dx[]={-1,0,1,0};
    //int dy[]={0,1,0,-1};

    /*
    bool prime[100010];
    void sieve(){
        fill(prime,prime+100010,true);
        prime[0]=prime[1]=false;

        for(lli i=2;i<100010;i++){
            if(prime[i]){
                for(lli j=i*i;j<100010;j+=i)
                {prime[j]=false;}
            }
        }
    }
*/
     prii operator +(const prii& l , const prii& r){
         prii ret;
         ret.f=l.f+r.f;
         ret.s=l.s+r.s;
         return ret;
     }

    struct cmp{
        bool operator()(pair<prii,int> const & l,pair<prii,int> const & r) {
            return (l.f.f!=r.f.f)?(l.f.f<r.f.f):(l.f.s<r.f.s);
        }
    }myobject;

    int n,k,l,r,x,y;
    vector<pair<prii,int>> v;
    lli ans=0;
    set<pair<prii,int>> id;

    int main(){
        if(LOCAL){
            freopen("C:\\Users\\Smit Patel\\Desktop\\Questions\\This week\\input6.txt","r",stdin);
            freopen("C:\\Users\\Smit Patel\\Desktop\\Questions\\This week\\output6.txt","w",stdout);
        }

        v.pb(mp(mp(INT_MIN,INT_MIN),0));

        si2(n,k);
        FORi(1,n){
            si2(x,y);
            v.pb(mp(mp(x,y),i));
        }

        sort(all(v),myobject);

        set<pair<prii,int>> en,st;

        FORi(1,k){
            int l=v[i].f.f,r=v[i].f.s,idx=v[i].s;
            st.insert(mp(mp(l,r),idx));
            en.insert(mp(mp(r,l),idx));
        }

        FORi(k+1,n){
            if(en.size()==k){
                lli a=(en.begin())->f.f;
                lli b=(st.rbegin())->f.f;
           //     debugs(b,a);
                if(a-b+1>ans){
                    ans=a-b+1;
                    id=st;
                }
            }

            int l=v[i].f.f,r=v[i].f.s,idx=v[i].s;
            if(st.size()>0 && en.begin()->f.f<r){
                auto p=*en.begin();
                en.erase(en.begin());
                st.erase(mp(mp(p.f.s,p.f.f),p.s));
                st.insert(mp(mp(l,r),idx));
                en.insert(mp(mp(r,l),idx));
            }

            if(en.size()==k){
                lli a=(en.begin())->f.f;
                lli b=(st.rbegin())->f.f;
                if(a-b+1>ans){
                    ans=a-b+1;
                    id=st;
                }
            }
        }

        if(ans==0){
            pi(ans);pn;
            FORi(1,k){pi(i);ps;}
        }
        else{
            pi(ans);pn;
            for(auto p:id){pi(p.s);ps;}
        }

        return 0;
    }


    #include<bits/stdc++.h>
    using namespace std;

    #define LOCAL 0

    #define length(a) (sizeof(a)/sizeof(a[0]))
    #define print(v,i,x) for(int j=i;j<=x;j++){cout<<v[j]<<" ";}cout<<endl;
    #define pb push_back
    #define mp make_pair
    #define lli long long int
    #define ulli unsigned long long int
    #define all(x) x.begin(),x.end()
    #define f first
    #define s second

    #define si(x) scanf("%d",&x);
    #define sli(x) scanf("%ld",&x);
    #define slli(x) scanf("%lld",&x);
    #define si2(x,y) {si(x);si(y);}
    #define si3(x,y,z) {si(x);si(y);si(z);}
    #define slli2(x,y) {slli(x);slli(y);}
    #define slli3(x,y,z) {slli(x);slli(y);slli(z);}

    #define pi(x) printf("%d",x);
    #define pi2(x,y) printf("%d %d",x,y);
    #define pi3(x,y,z) printf("%d %d %d",x,y,z);
    #define pli(x) printf("%ld",x);
    #define plli(x) printf("%lld",x);
    #define plli2(x,y) printf("%lld %lld",x,y);
    #define plli3(x,y,z) printf("%lld %lld %lld",x,y,z);
    #define pn printf("\n");
    #define ps printf(" ");
    #define pc(c) printf("%c",c);

    #define FOR(n) for(int i=0;i<n;i++)
    #define FORi(x,n) for(int i=x;i<=n;i++)
    #define FORj(x,n) for(int j=x;j<=n;j++)
    #define FORk(x,n) for(int k=x;k<=n;k++)
    #define ROFi(x,n) for(int i=x;i>=n;i--)
    #define ROFj(x,n) for(int j=x;j>=n;j--)
    #define ROFk(x,n) for(int k=x;k>=n;k--)

    #define debug(x) cout << "  - " << #x << ": " << x << endl;
    #define debugs(x, y) cout << "  - " << #x << ": " << x << "         " << #y << ": " << y << endl;
    #define debugss(x, y, z) cout << "  - " << #x << ": " << x << "         " << #y << ": " << y << "         " << #z << ": " << z <<  endl;
    #define fastIO 	std::ios::sync_with_stdio(false);cin.tie(NULL);

    typedef vector<int> vi;
    typedef vector<long> vli;
    typedef vector<long long> vlli;
    typedef vector<string> vstr;

    typedef pair<int,int> prii;
    typedef pair<int,lli> prilli;
    typedef pair<lli,int> prllii;
    typedef pair<lli,lli> prllilli;

    template <class T>T max3(T a,T b,T c){return max2(max2(a,b),c);}
    template <class T>T min3(T a,T b,T c){return min2(min2(a,b),c);}
    template <class T>T max4(T a,T b,T c,T d){return max2(max2(a,b),max2(c,d));}
    template <class T>T min4(T a,T b,T c,T d){return min2(min2(a,b),max2(c,d));}

    const lli mod = 1000000007ll;
    const lli MOD = 1000000009ll;
    const lli INF = LLONG_MAX/10;
    const int inf = INT_MAX/2;

    lli count_bit(lli _x){lli _ret=0;while(_x){if(_x%2==1)_ret++;_x/=2;}return _ret;}
    lli check_bit(lli _mask,lli _i){lli x=1;return (_mask&(x<<_i))==0?0:1;}
    lli set_bit(lli _mask,lli _i){lli x=1;_mask=_mask|(x<<_i);return _mask;}
    lli powermod(lli _a,lli _b,lli _m=mod){lli _r=1;while(_b){if(_b%2==1)_r=(_r*_a)%_m;_b/=2;_a=(_a*_a)%_m;}return _r;}
    lli power(lli _a,lli _b){lli _r=1;while(_b){if(_b%2==1)_r=(_r*_a);_b/=2;_a=(_a*_a);}return _r;}
    lli add(lli a,lli b,lli m=mod){lli x=a+b;while(x>=m)x-=m;return x;}
    lli sub(lli a,lli b,lli m=mod){lli x=a-b;while(x<0)x+=m;return x;}
    lli mul(lli a,lli b,lli m=mod){lli x=a*b;x%=m;return x;}
    lli gcd(lli a,lli b){ if(a<b) {a=a^b;b=a^b;a=a^b;} if(b==0)return a; lli t; while(b){t=b; b=a%b; a=t;}return a;}
    lli lcm(lli a,lli b){ return (a*b)/gcd(a,b); }

     vector<string> _split(const string& s, char c) {
        vector<string> v;
        stringstream ss(s);
        string x;
        while (getline(ss, x, c))
            v.emplace_back(x);
        return v;
    }

    //	int dx[]={-1,-1,0,1,1,1,0,-1};
    //	int dy[]={0,1,1,1,0,-1,-1,-1};

    //int dx[]={-1,0,1,0};
    //int dy[]={0,1,0,-1};

    /*
    bool prime[100010];
    void sieve(){
        fill(prime,prime+100010,true);
        prime[0]=prime[1]=false;

        for(lli i=2;i<100010;i++){
            if(prime[i]){
                for(lli j=i*i;j<100010;j+=i)
                {prime[j]=false;}
            }
        }
    }
*/
     prii operator +(const prii& l , const prii& r){
         prii ret;
         ret.f=l.f+r.f;
         ret.s=l.s+r.s;
         return ret;
     }

    struct cmp{
        bool operator()(pair<prii,int> const & l,pair<prii,int> const & r) {
            return (l.f.f!=r.f.f)?(l.f.f<r.f.f):(l.f.s<r.f.s);
        }
    }myobject;

    prii tree[1200010];
    int n,k,l,r,x,y;
    vector<pair<prii,int>> v;

    prii merg(prii p1,prii p2){
        prii p;
        p.f=max(p1.f,p2.f);
        p.s=min(p1.s,p2.s);
        return p;
    }

    void build(int node,int st,int en){
		if(st==en){
            tree[node].f=v[st].f.f;
            tree[node].s=v[st].f.s;
			return;
		}

		int mid=(st+en)>>1;
		build(2*node,st,mid);
		build(2*node+1,mid+1,en);

		tree[node]=merg(tree[2*node],tree[2*node+1]);
	}

	prii query(int node,int st,int en,int l,int r){
		if(l>en || r<st)
			return mp(INT_MIN,INT_MAX);

		if(l<=st && en<=r)
			return tree[node];

		int mid=(st+en)>>1;
		prii p1=query(2*node,st,mid,l,r);
		prii p2=query(2*node+1,mid+1,en,l,r);

		return merg(p1,p2);
	}

    int main(){
        if(LOCAL){
            freopen("C:\\Users\\Smit Patel\\Desktop\\Questions\\This week\\input6.txt","r",stdin);
            freopen("C:\\Users\\Smit Patel\\Desktop\\Questions\\This week\\output6.txt","w",stdout);
        }

        v.pb(mp(mp(INT_MIN,INT_MIN),0));

        si2(n,k);
        FORi(1,n){
            si2(x,y);
            v.pb(mp(mp(x,y),i));
        }

        sort(all(v),myobject);

        build(1,1,n);

        int idx=1,ans=0;
        FORi(1,n-k+1){
            prii tmp=query(1,1,n,i,i+k-1);
            if(tmp.s-tmp.f+1>ans){
                ans=tmp.s-tmp.f+1;
                idx=i;
            }
        }

        pi(ans);pn;
        FORi(idx,idx+k-1)
        {
            pi(v[i].s);ps;
        }

        return 0;
    }


    #include<bits/stdc++.h>
    using namespace std;

    #define LOCAL 0

    #define length(a) (sizeof(a)/sizeof(a[0]))
    #define print(v,i,x) for(int j=i;j<=x;j++){cout<<v[j]<<" ";}cout<<endl;
    #define pb push_back
    #define mp make_pair
    #define lli long long int
    #define ulli unsigned long long int
    #define all(x) x.begin(),x.end()
    #define f first
    #define s second

    #define si(x) scanf("%d",&x);
    #define sli(x) scanf("%ld",&x);
    #define slli(x) scanf("%lld",&x);
    #define si2(x,y) {si(x);si(y);}
    #define si3(x,y,z) {si(x);si(y);si(z);}
    #define slli2(x,y) {slli(x);slli(y);}
    #define slli3(x,y,z) {slli(x);slli(y);slli(z);}

    #define pi(x) printf("%d",x);
    #define pi2(x,y) printf("%d %d",x,y);
    #define pi3(x,y,z) printf("%d %d %d",x,y,z);
    #define pli(x) printf("%ld",x);
    #define plli(x) printf("%lld",x);
    #define plli2(x,y) printf("%lld %lld",x,y);
    #define plli3(x,y,z) printf("%lld %lld %lld",x,y,z);
    #define pn printf("\n");
    #define ps printf(" ");
    #define pc(c) printf("%c",c);

    #define FOR(n) for(int i=0;i<n;i++)
    #define FORi(x,n) for(int i=x;i<=n;i++)
    #define FORj(x,n) for(int j=x;j<=n;j++)
    #define FORk(x,n) for(int k=x;k<=n;k++)
    #define ROFi(x,n) for(int i=x;i>=n;i--)
    #define ROFj(x,n) for(int j=x;j>=n;j--)
    #define ROFk(x,n) for(int k=x;k>=n;k--)

    #define debug(x) cout << "  - " << #x << ": " << x << endl;
    #define debugs(x, y) cout << "  - " << #x << ": " << x << "         " << #y << ": " << y << endl;
    #define debugss(x, y, z) cout << "  - " << #x << ": " << x << "         " << #y << ": " << y << "         " << #z << ": " << z <<  endl;
    #define fastIO 	std::ios::sync_with_stdio(false);cin.tie(NULL);

    typedef vector<int> vi;
    typedef vector<long> vli;
    typedef vector<long long> vlli;
    typedef vector<string> vstr;

    typedef pair<int,int> prii;
    typedef pair<int,lli> prilli;
    typedef pair<lli,int> prllii;
    typedef pair<lli,lli> prllilli;

    template <class T>T max3(T a,T b,T c){return max2(max2(a,b),c);}
    template <class T>T min3(T a,T b,T c){return min2(min2(a,b),c);}
    template <class T>T max4(T a,T b,T c,T d){return max2(max2(a,b),max2(c,d));}
    template <class T>T min4(T a,T b,T c,T d){return min2(min2(a,b),max2(c,d));}

    const lli mod = 1000000007ll;
    const lli MOD = 1000000009ll;
    const lli INF = LLONG_MAX/10;
    const int inf = INT_MAX/2;

    lli count_bit(lli _x){lli _ret=0;while(_x){if(_x%2==1)_ret++;_x/=2;}return _ret;}
    lli check_bit(lli _mask,lli _i){lli x=1;return (_mask&(x<<_i))==0?0:1;}
    lli set_bit(lli _mask,lli _i){lli x=1;_mask=_mask|(x<<_i);return _mask;}
    lli powermod(lli _a,lli _b,lli _m=mod){lli _r=1;while(_b){if(_b%2==1)_r=(_r*_a)%_m;_b/=2;_a=(_a*_a)%_m;}return _r;}
    lli power(lli _a,lli _b){lli _r=1;while(_b){if(_b%2==1)_r=(_r*_a);_b/=2;_a=(_a*_a);}return _r;}
    lli add(lli a,lli b,lli m=mod){lli x=a+b;while(x>=m)x-=m;return x;}
    lli sub(lli a,lli b,lli m=mod){lli x=a-b;while(x<0)x+=m;return x;}
    lli mul(lli a,lli b,lli m=mod){lli x=a*b;x%=m;return x;}
    lli gcd(lli a,lli b){ if(a<b) {a=a^b;b=a^b;a=a^b;} if(b==0)return a; lli t; while(b){t=b; b=a%b; a=t;}return a;}
    lli lcm(lli a,lli b){ return (a*b)/gcd(a,b); }

     vector<string> _split(const string& s, char c) {
        vector<string> v;
        stringstream ss(s);
        string x;
        while (getline(ss, x, c))
            v.emplace_back(x);
        return v;
    }

    //	int dx[]={-1,-1,0,1,1,1,0,-1};
    //	int dy[]={0,1,1,1,0,-1,-1,-1};

    //int dx[]={-1,0,1,0};
    //int dy[]={0,1,0,-1};

    /*
    bool prime[100010];
    void sieve(){
        fill(prime,prime+100010,true);
        prime[0]=prime[1]=false;

        for(lli i=2;i<100010;i++){
            if(prime[i]){
                for(lli j=i*i;j<100010;j+=i)
                {prime[j]=false;}
            }
        }
    }
*/
     prii operator +(const prii& l , const prii& r){
         prii ret;
         ret.f=l.f+r.f;
         ret.s=l.s+r.s;
         return ret;
     }

    struct cmp{
        bool operator()(pair<prii,int> const & l,pair<prii,int> const & r) {
            return (l.f.f!=r.f.f)?(l.f.f<r.f.f):(l.f.s<r.f.s);
        }
    }myobject;

    prii tree[1200010];
    int n,k,l,r,x,y;
    vector<pair<prii,int>> v;

    prii merg(prii p1,prii p2){
        prii p;
        p.f=max(p1.f,p2.f);
        p.s=min(p1.s,p2.s);
        return p;
    }

    void build(int node,int st,int en){
		if(st==en){
            tree[node].f=v[st].f.f;
            tree[node].s=v[st].f.s;
			return;
		}

		int mid=(st+en)>>1;
		build(2*node,st,mid);
		build(2*node+1,mid+1,en);

		tree[node]=merg(tree[2*node],tree[2*node+1]);
	}

	prii query(int node,int st,int en,int l,int r){
		if(l>en || r<st)
			return mp(INT_MIN,INT_MAX);

		if(l<=st && en<=r)
			return tree[node];

		int mid=(st+en)>>1;
		prii p1=query(2*node,st,mid,l,r);
		prii p2=query(2*node+1,mid+1,en,l,r);

		return merg(p1,p2);
	}

    int main(){
        if(LOCAL){
            freopen("C:\\Users\\Smit Patel\\Desktop\\Questions\\This week\\input6.txt","r",stdin);
            freopen("C:\\Users\\Smit Patel\\Desktop\\Questions\\This week\\output6.txt","w",stdout);
        }

        v.pb(mp(mp(0,0),0));

        si2(n,k);
        FORi(1,n){
            si2(x,y);
            v.pb(mp(mp(x,y),i));
        }

        sort(all(v),myobject);

        build(1,1,n);

        int idx=1,ans=0;
        FORi(1,n-k+1){
            prii tmp=query(1,1,n,i,i+k-1);
            if(tmp.s-tmp.f+1>ans){
                ans=tmp.s-tmp.f+1;
                idx=i;
            }
        }

        pi(ans);pn;
        FORi(idx,idx+k-1)
        {
            pi(v[i].s);ps;
        }

        return 0;
    }


    #include<bits/stdc++.h>
	#include<bits/stdc++.h>
	#include<bits/stdc++.h>
	using namespace std;

	#define length(a) (sizeof(a)/sizeof(a[0]))
	#define print(v,i,x) for(int j=i;j<=x;j++){cout<<v[j]<<" ";}cout<<endl;
	#define pb push_back
	#define mp make_pair
	#define lli long long int
	#define ulli unsigned long long int
	#define all(x) x.begin(),x.end()
	#define f first
	#define s second

	#define si(x) scanf("%d",&x);
	#define sli(x) scanf("%ld",&x);
	#define slli(x) scanf("%lld",&x);
	#define slu(x) scanf("%lu",&x);
	#define sllu(x) scanf("%llu",&x);
	#define si2(x,y) si(x);si(y);
	#define si3(x,y,z) si(x);si(y);si(z);
	#define slli2(x,y) slli(x);slli(y);
	#define slli3(x,y,z) slli(x);slli(y);slli(z);

	#define pi(x) printf("%d",x);
	#define pli(x) printf("%ld",x);
	#define plli(x) printf("%lld",x);
	#define plu(x) printf("%lu",x);
	#define pllu(x) printf("llu",x);
	#define pn printf("\n");
	#define ps printf(" ");
	#define pc(c) printf("%c",c);

	#define FOR(n) for(int i=0;i<n;i++)
	#define FORi(x,n) for(int i=x;i<=n;i++)
	#define FORj(x,n) for(int j=x;j<=n;j++)
	#define FORk(x,n) for(int k=x;k<=n;k++)
	#define ROFi(x,n) for(int i=x;i>=n;i--)
	#define ROFj(x,n) for(int j=x;j>=n;j--)
	#define ROFk(x,n) for(int k=x;k>=n;k--)

	#define debug(x) cout << "  - " << #x << ": " << x << endl;
	#define debugs(x, y) cout << "  - " << #x << ": " << x << "         " << #y << ": " << y << endl;
	#define fastIO 	std::ios::sync_with_stdio(false);cin.tie(NULL);

	typedef vector<int> vi;
	typedef vector<long> vli;
	typedef vector<long long> vlli;
	typedef vector<string> vstr;

	typedef pair<int,int> prii;
	typedef pair<long,int> prlii;
	typedef pair<int,long> prili;
	typedef pair<int,lli> prilli;
	typedef pair<lli,int> prllii;
	typedef pair<long,lli> prlilli;
	typedef pair<lli,long> prllili;
	typedef pair<lli,lli> prllilli;
	typedef pair<long,long> prlili;

	template <class T>T max2(T a,T b){return a<b?b:a;}
	template <class T>T min2(T a,T b){return a<b?a:b;}
	template <class T>T max3(T a,T b,T c){return max2(max2(a,b),c);}
	template <class T>T min3(T a,T b,T c){return min2(min2(a,b),c);}
	template <class T>T max4(T a,T b,T c,T d){return max2(max2(a,b),max2(c,d));}
	template <class T>T min4(T a,T b,T c,T d){return min2(min2(a,b),max2(c,d));}

	const lli mod = 1000000007ll;
	const lli MOD = 1000000009ll;

	lli bit_count(lli _x){lli _ret=0;while(_x){if(_x%2==1)_ret++;_x/=2;}return _ret;}
	lli bit(lli _mask,lli _i){lli x=1;return (_mask&(x<<_i))==0?0:1;}
	lli powermod(lli _a,lli _b,lli _m=mod){lli _r=1;while(_b){if(_b%2==1)_r=(_r*_a)%_m;_b/=2;_a=(_a*_a)%_m;}return _r;}
	lli power(lli _a,lli _b){lli _r=1;while(_b){if(_b%2==1)_r=(_r*_a);_b/=2;_a=(_a*_a);}return _r;}
	lli add(lli a,lli b,lli m=mod){lli x=a+b;while(x>=m)x-=m;return x;}
	lli sub(lli a,lli b,lli m=mod){lli x=a-b;while(x<0)x+=m;return x;}
	lli mul(lli a,lli b,lli m=mod){lli x=a*b;x%=m;return x;}
	lli gcd(lli a,lli b){ if(a<b) {a=a^b;b=a^b;a=a^b;} if(b==0)return a; lli t; while(b){t=b; b=a%b; a=t;}return a;}
	lli lcm(lli a,lli b){ return (a*b)/gcd(a,b); }

//	int dx[]={-1,-1,0,1,1,1,0,-1};
//	int dy[]={0,1,1,1,0,-1,-1,-1};

	/*
	vector<string> _split(const string& s, char c) {
		vector<string> v;
		stringstream ss(s);
		string x;
		while (getline(ss, x, c))
			v.emplace_back(x);
		return v;
	}
	*/
	 prii operator +(const prii& l , const prii& r){
		 prii ret;
		 ret.f=l.f+r.f;
		 ret.s=l.s+r.s;
		 return ret;
	 }

	struct cmp{
		bool operator()(pair<prllilli,int>  const & l,pair<prllilli,int>  const & r) {
			if(l.f.s!=r.f.s)
			return l.f.s<r.f.s;
			else
			return l.f.f<r.f.f;
		}
	}myobject;

	int n,k;
	vector<pair<prllilli,int>> c,v;
    lli x,y,ans=0;
    vi f;
    set<pair<prllilli,int>,cmp> s;
    multiset<lli> st;

    bool check(lli m){
        s.clear();
        st.clear();

        FOR(v.size()){

     //       cout<<"-----------------------\n";
      //      debug(i);
      //      for(auto p:s)
      //      cout<<p.f.f<<" "<<p.f.s<<"  "<<p.s<<endl;

            if(s.size()==k){
                lli l=*(--st.end());
                lli r=s.begin()->f.s;
        //         debugs(l,r);
                if(r-l+1>=m){
         //          debug(m);
                    f.clear();
                    for(auto p:s)
                    f.pb(p.s);

                    return true;
                }

                lli x=s.begin()->f.f;
                st.erase(st.find(x));
                s.erase(s.begin());

            }

            while(s.size()>0 && s.begin()->f.s < v[i].f.f){
                lli x=s.begin()->f.f;
                st.erase(st.find(x));
                s.erase(s.begin());
            }

            s.insert(mp(mp(v[i].f.f,v[i].f.s),v[i].s));
            st.insert(v[i].f.f);

        }

        return false;
    }

	int main(){

        si(n);si(k);

        FOR(n){
            slli(x);slli(y);
            c.pb(mp(mp(x,y),i+1));
        }

        c.pb(mp(mp(LLONG_MAX/2,LLONG_MAX/2),n+1));
        v=c;

        sort(all(v),myobject);
    //    cout<<check(31);
        lli l=1,r=2000000010;

        while(r>=l){
            lli mid=l+(r-l)/2;

            if(check(mid)){
                ans=mid;
                l=mid+1;

            }
            else
            {r=mid-1;}

        }

        plli(ans);pn;
    //    debug(f.size());
        if(f.size()>0){
            sort(all(f));
            for(auto p:f)
            {pi(p);ps;}
        }
        else{
            FORi(1,k)
            {pi(i);ps;}
        }

		return 0;

	}


  #include<bits/stdc++.h>
	#include<bits/stdc++.h>
	#include<bits/stdc++.h>
	using namespace std;

	#define length(a) (sizeof(a)/sizeof(a[0]))
	#define print(v,i,x) for(int j=i;j<=x;j++){cout<<v[j]<<" ";}cout<<endl;
	#define pb push_back
	#define mp make_pair
	#define lli long long int
	#define ulli unsigned long long int
	#define all(x) x.begin(),x.end()
	#define f first
	#define s second

	#define si(x) scanf("%d",&x);
	#define sli(x) scanf("%ld",&x);
	#define slli(x) scanf("%lld",&x);
	#define slu(x) scanf("%lu",&x);
	#define sllu(x) scanf("%llu",&x);
	#define si2(x,y) si(x);si(y);
	#define si3(x,y,z) si(x);si(y);si(z);
	#define slli2(x,y) slli(x);slli(y);
	#define slli3(x,y,z) slli(x);slli(y);slli(z);

	#define pi(x) printf("%d",x);
	#define pli(x) printf("%ld",x);
	#define plli(x) printf("%lld",x);
	#define plu(x) printf("%lu",x);
	#define pllu(x) printf("llu",x);
	#define pn printf("\n");
	#define ps printf(" ");
	#define pc(c) printf("%c",c);

	#define FOR(n) for(int i=0;i<n;i++)
	#define FORi(x,n) for(int i=x;i<=n;i++)
	#define FORj(x,n) for(int j=x;j<=n;j++)
	#define FORk(x,n) for(int k=x;k<=n;k++)
	#define ROFi(x,n) for(int i=x;i>=n;i--)
	#define ROFj(x,n) for(int j=x;j>=n;j--)
	#define ROFk(x,n) for(int k=x;k>=n;k--)

	#define debug(x) cout << "  - " << #x << ": " << x << endl;
	#define debugs(x, y) cout << "  - " << #x << ": " << x << "         " << #y << ": " << y << endl;
	#define fastIO 	std::ios::sync_with_stdio(false);cin.tie(NULL);

	typedef vector<int> vi;
	typedef vector<long> vli;
	typedef vector<long long> vlli;
	typedef vector<string> vstr;

	typedef pair<int,int> prii;
	typedef pair<long,int> prlii;
	typedef pair<int,long> prili;
	typedef pair<int,lli> prilli;
	typedef pair<lli,int> prllii;
	typedef pair<long,lli> prlilli;
	typedef pair<lli,long> prllili;
	typedef pair<lli,lli> prllilli;
	typedef pair<long,long> prlili;

	template <class T>T max2(T a,T b){return a<b?b:a;}
	template <class T>T min2(T a,T b){return a<b?a:b;}
	template <class T>T max3(T a,T b,T c){return max2(max2(a,b),c);}
	template <class T>T min3(T a,T b,T c){return min2(min2(a,b),c);}
	template <class T>T max4(T a,T b,T c,T d){return max2(max2(a,b),max2(c,d));}
	template <class T>T min4(T a,T b,T c,T d){return min2(min2(a,b),max2(c,d));}

	const lli mod = 1000000007ll;
	const lli MOD = 1000000009ll;

	lli bit_count(lli _x){lli _ret=0;while(_x){if(_x%2==1)_ret++;_x/=2;}return _ret;}
	lli bit(lli _mask,lli _i){lli x=1;return (_mask&(x<<_i))==0?0:1;}
	lli powermod(lli _a,lli _b,lli _m=mod){lli _r=1;while(_b){if(_b%2==1)_r=(_r*_a)%_m;_b/=2;_a=(_a*_a)%_m;}return _r;}
	lli power(lli _a,lli _b){lli _r=1;while(_b){if(_b%2==1)_r=(_r*_a);_b/=2;_a=(_a*_a);}return _r;}
	lli add(lli a,lli b,lli m=mod){lli x=a+b;while(x>=m)x-=m;return x;}
	lli sub(lli a,lli b,lli m=mod){lli x=a-b;while(x<0)x+=m;return x;}
	lli mul(lli a,lli b,lli m=mod){lli x=a*b;x%=m;return x;}
	lli gcd(lli a,lli b){ if(a<b) {a=a^b;b=a^b;a=a^b;} if(b==0)return a; lli t; while(b){t=b; b=a%b; a=t;}return a;}
	lli lcm(lli a,lli b){ return (a*b)/gcd(a,b); }

//	int dx[]={-1,-1,0,1,1,1,0,-1};
//	int dy[]={0,1,1,1,0,-1,-1,-1};

	/*
	vector<string> _split(const string& s, char c) {
		vector<string> v;
		stringstream ss(s);
		string x;
		while (getline(ss, x, c))
			v.emplace_back(x);
		return v;
	}
	*/
	 prii operator +(const prii& l , const prii& r){
		 prii ret;
		 ret.f=l.f+r.f;
		 ret.s=l.s+r.s;
		 return ret;
	 }

	struct cmp{
		bool operator()(pair<prllilli,int>  const & l,pair<prllilli,int>  const & r) {
			if(l.f.s!=r.f.s)
			return l.f.s<r.f.s;
			else
			return l.f.f<r.f.f;
		}
	}myobject;

	struct cmp1{
		bool operator()(pair<prllilli,int>  const & l,pair<prllilli,int>  const & r) {
			if(l.f.f!=r.f.f)
			return l.f.f<r.f.f;
			else
			return l.f.s>r.f.s;
		}
	}myobject1;

	int n,k;
	vector<pair<prllilli,int>> c,v;
    lli x,y,ans=0;
    vi f;
    set<pair<prllilli,int>,cmp> s;
    multiset<lli> st;

    void check(){
        s.clear();
        st.clear();

        FOR(v.size()){

 //          cout<<"-----------------------\n";
 //           debugs(i,s.size());
   //         for(auto p:s)
   //         cout<<p.f.f<<" "<<p.f.s<<"  "<<p.s<<endl;

            if(s.size()==k){
                lli l=*(--st.end());
                lli r=s.begin()->f.s;
      //           debugs(l,r);
                if(r-l+1>=ans){
      //             debug(m);
                    f.clear();
                    int cnt=0;
                    for(auto p:s)
                    {f.pb(p.s);}
                    ans=max(ans,r-l+1);

                }

                lli x=s.begin()->f.f;
                st.erase(st.find(x));
                s.erase(s.begin());

            }

            while(s.size()>0 && s.begin()->f.s < v[i].f.s){
                lli x=s.begin()->f.f;
                st.erase(st.find(x));
                s.erase(s.begin());
            }
            if(s.size()<k){
                s.insert(mp(mp(v[i].f.f,v[i].f.s),v[i].s));
                st.insert(v[i].f.f);
            }

        }

    }

	int main(){

        si(n);si(k);
        lli mn=LLONG_MIN,mx=LLONG_MAX;
        FOR(n){
            slli(x);slli(y);
            mn=min(mn,x);
            mx=max(mx,y);
            c.pb(mp(mp(x,y),i+1));
        }

        c.pb(mp(mp(LLONG_MAX/2,LLONG_MAX/2),n+1));
        v=c;

        sort(all(v),myobject1);

        lli l=1,r=200000010;
       /*
        while(r>=l){
            lli mid=l+(r-l)/2;

            if(check(mid)){
                ans=mid;
                l=mid+1;

            }
            else
            {r=mid-1;}

        }*/
        check();
        plli(ans);pn;
    //    debug(f.size());
        if(f.size()>0){
            sort(all(f));
            for(auto p:f)
            {pi(p);ps;}
        }
        else{
            FORi(1,k)
            {pi(i);ps;}
        }

		return 0;

	}


    #include<bits/stdc++.h>
    using namespace std;

    static int LOCAL=0;

    #define F0(a) memset(a,0,sizeof(a));
    #define print(v,i,x) for(int j=i;j<=x;j++){cout<<v[j]<<" ";}cout<<endl;
    #define pb push_back
    #define mp make_pair
    #define lli long long int
    #define ulli unsigned long long int
    #define all(x) x.begin(),x.end()
    #define sz(x) ((int)x.size())
    #define f first
    #define s second

    #define si(x) scanf("%d",&x)
    #define slli(x) scanf("%lld",&x)
    #define si2(x,y) scanf("%d %d",&x,&y)
    #define si3(x,y,z) scanf("%d %d %d",&x,&y,&z)
    #define slli2(x,y) scanf("%lld %lld",&x,&y)
    #define slli3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)

    #define pi(x) printf("%d",x)
    #define pi2(x,y) printf("%d %d",x,y)
    #define pi3(x,y,z) printf("%d %d %d",x,y,z)
    #define plli(x) printf("%lld",x)
    #define plli2(x,y) printf("%lld %lld",x,y)
    #define plli3(x,y,z) printf("%lld %lld %lld",x,y,z)
    #define pn printf("\n")
    #define ps printf(" ")
    #define pc(c) printf("%c",c)

    #define FOR(i,x,n) for(int i=x;i<=n;i++)
    #define ROF(i,x,n) for(int i=x;i>=n;i--)
    #define fr(i,x,n) for(int i=x;i<n;i++)

    #define debug(x) cout << "  - " << #x << ": " << x << endl;
    #define debugs(x, y) cout << "  - " << #x << ": " << x << "         " << #y << ": " << y << endl;
    #define debugss(x, y, z) cout << "  - " << #x << ": " << x << "         " << #y << ": " << y << "         " << #z << ": " << z <<  endl;
    #define fastIO  std::ios::sync_with_stdio(false);cin.tie(NULL);
    #define cut cout<<"------------------------------------------\n";
    #define cut1 cout<<"******************************************\n";

    typedef vector<int> vi;
    typedef vector<lli> vlli;
    typedef vector<pair<int,int>> vii;

    typedef pair<int,int> prii;
    typedef pair<int,lli> prilli;
    typedef pair<lli,int> prllii;
    typedef pair<lli,lli> prllilli;

    const lli mod = 1000000007ll;
    const lli MOD = 1000000009ll;
    const lli INF = LLONG_MAX/10;
    const int inf = INT_MAX/10;

    lli powermod(lli _a,lli _b,lli _m=mod){lli _r=1;while(_b){if(_b%2==1)_r=(_r*_a)%_m;_b/=2;_a=(_a*_a)%_m;}return _r;}
    lli power(lli _a,lli _b){lli _r=1;while(_b){if(_b%2==1)_r=(_r*_a);_b/=2;_a=(_a*_a);}return _r;}
    lli add(lli a,lli b,lli m=mod){lli x=a+b;while(x>=m)x-=m;return x;}
    lli sub(lli a,lli b,lli m=mod){lli x=a-b;while(x<0)x+=m;return x;}
    lli mul(lli a,lli b,lli m=mod){return ((a%m)*(b%m))%m;}
    lli gcd(lli a,lli b){while(a&&b)a>b?a%=b:b%=a;return a+b;}
    lli lcm(lli a,lli b){return (max(a,b)/gcd(a,b))*min(a,b);}

    struct pair_hash {
        std::size_t operator () (const std::pair<int,int> &p) const {
            auto h1 = std::hash<lli>{}(p.first);
            auto h2 = std::hash<lli>{}(p.second);
            return add(h1,mul(h2,h1,MOD));
        }
    };

    struct cmp{
        bool operator()(prii const & l,prii const & r){
            return l.f<r.f;
        }
    }myobject;

    int n,k;
    multiset<pair<prllilli,int>> s,rs;
    vector<prllilli> v;

    int main(){

       si2(n,k);

       lli ans=0,x,y;

       FOR(i,1,n){
            slli2(x,y);
            v.pb({x,y});
            while(sz(s)>=k){
                auto p=*rs.begin();
                rs.erase(rs.begin());
                s.erase(s.find({{p.f.s,p.f.f},p.s}));
            }
            s.insert({{x,y},i});
            rs.insert({{y,x},i});
            if(sz(s)==k){ans=max(ans,rs.begin()->f.f-s.rbegin()->f.f+1);}
       }

       s.clear();
       rs.clear();
       for(int i=0;i<sz(v);i++){
            x=v[i].f;
            y=v[i].s;
            while(sz(s)>=k){
                auto p=*rs.begin();
                rs.erase(rs.begin());
                s.erase(s.find({{p.f.s,p.f.f},p.s}));
            }
            s.insert({{x,y},i+1});
            rs.insert({{y,x},i+1});
            if(sz(s)==k && rs.begin()->f.f-s.rbegin()->f.f+1 == ans){
                plli(ans);pn;
                for(auto p:s)pi(p.s),ps;
                return 0;
            }
       }

       cout<<ans;

        return 0;
    }


    #include<bits/stdc++.h>
    using namespace std;

    #define LOCAL 0

    #define length(a) (sizeof(a)/sizeof(a[0]))
    #define print(v,i,x) for(int j=i;j<=x;j++){cout<<v[j]<<" ";}cout<<endl;
    #define pb push_back
    #define mp make_pair
    #define lli long long int
    #define ulli unsigned long long int
    #define all(x) x.begin(),x.end()
    #define f first
    #define s second

    #define si(x) scanf("%d",&x);
    #define sli(x) scanf("%ld",&x);
    #define slli(x) scanf("%lld",&x);
    #define si2(x,y) {si(x);si(y);}
    #define si3(x,y,z) {si(x);si(y);si(z);}
    #define slli2(x,y) {slli(x);slli(y);}
    #define slli3(x,y,z) {slli(x);slli(y);slli(z);}

    #define pi(x) printf("%d",x);
    #define pi2(x,y) printf("%d %d",x,y);
    #define pi3(x,y,z) printf("%d %d %d",x,y,z);
    #define pli(x) printf("%ld",x);
    #define plli(x) printf("%lld",x);
    #define plli2(x,y) printf("%lld %lld",x,y);
    #define plli3(x,y,z) printf("%lld %lld %lld",x,y,z);
    #define pn printf("\n");
    #define ps printf(" ");
    #define pc(c) printf("%c",c);

    #define FOR(n) for(int i=0;i<n;i++)
    #define FORi(x,n) for(int i=x;i<=n;i++)
    #define FORj(x,n) for(int j=x;j<=n;j++)
    #define FORk(x,n) for(int k=x;k<=n;k++)
    #define ROFi(x,n) for(int i=x;i>=n;i--)
    #define ROFj(x,n) for(int j=x;j>=n;j--)
    #define ROFk(x,n) for(int k=x;k>=n;k--)

    #define debug(x) cout << "  - " << #x << ": " << x << endl;
    #define debugs(x, y) cout << "  - " << #x << ": " << x << "         " << #y << ": " << y << endl;
    #define debugss(x, y, z) cout << "  - " << #x << ": " << x << "         " << #y << ": " << y << "         " << #z << ": " << z <<  endl;
    #define fastIO 	std::ios::sync_with_stdio(false);cin.tie(NULL);

    typedef vector<int> vi;
    typedef vector<long> vli;
    typedef vector<long long> vlli;
    typedef vector<string> vstr;

    typedef pair<int,int> prii;
    typedef pair<int,lli> prilli;
    typedef pair<lli,int> prllii;
    typedef pair<lli,lli> prllilli;

    template <class T>T max3(T a,T b,T c){return max2(max2(a,b),c);}
    template <class T>T min3(T a,T b,T c){return min2(min2(a,b),c);}
    template <class T>T max4(T a,T b,T c,T d){return max2(max2(a,b),max2(c,d));}
    template <class T>T min4(T a,T b,T c,T d){return min2(min2(a,b),max2(c,d));}

    const lli mod = 1000000007ll;
    const lli MOD = 1000000009ll;
    const lli INF = LLONG_MAX/10;
    const int inf = INT_MAX/2;

    lli count_bit(lli _x){lli _ret=0;while(_x){if(_x%2==1)_ret++;_x/=2;}return _ret;}
    lli check_bit(lli _mask,lli _i){lli x=1;return (_mask&(x<<_i))==0?0:1;}
    lli set_bit(lli _mask,lli _i){lli x=1;_mask=_mask|(x<<_i);return _mask;}
    lli powermod(lli _a,lli _b,lli _m=mod){lli _r=1;while(_b){if(_b%2==1)_r=(_r*_a)%_m;_b/=2;_a=(_a*_a)%_m;}return _r;}
    lli power(lli _a,lli _b){lli _r=1;while(_b){if(_b%2==1)_r=(_r*_a);_b/=2;_a=(_a*_a);}return _r;}
    lli add(lli a,lli b,lli m=mod){lli x=a+b;while(x>=m)x-=m;return x;}
    lli sub(lli a,lli b,lli m=mod){lli x=a-b;while(x<0)x+=m;return x;}
    lli mul(lli a,lli b,lli m=mod){lli x=a*b;x%=m;return x;}
    lli gcd(lli a,lli b){ if(a<b) {a=a^b;b=a^b;a=a^b;} if(b==0)return a; lli t; while(b){t=b; b=a%b; a=t;}return a;}
    lli lcm(lli a,lli b){ return (a*b)/gcd(a,b); }

     vector<string> _split(const string& s, char c) {
        vector<string> v;
        stringstream ss(s);
        string x;
        while (getline(ss, x, c))
            v.emplace_back(x);
        return v;
    }

    //	int dx[]={-1,-1,0,1,1,1,0,-1};
    //	int dy[]={0,1,1,1,0,-1,-1,-1};

    //int dx[]={-1,0,1,0};
    //int dy[]={0,1,0,-1};

    /*
    bool prime[100010];
    void sieve(){
        fill(prime,prime+100010,true);
        prime[0]=prime[1]=false;

        for(lli i=2;i<100010;i++){
            if(prime[i]){
                for(lli j=i*i;j<100010;j+=i)
                {prime[j]=false;}
            }
        }
    }
*/
     prii operator +(const prii& l , const prii& r){
         prii ret;
         ret.f=l.f+r.f;
         ret.s=l.s+r.s;
         return ret;
     }

    struct cmp{
        bool operator()(pair<prii,int> const & l,pair<prii,int> const & r) {
            return (l.f.f!=r.f.f)?(l.f.f<r.f.f):(l.f.s<r.f.s);
        }
    }myobject;

    int n,k,l,r,x,y;
    vector<pair<prii,int>> v;
    lli ans=0;
    set<pair<prii,int>> id;

    int main(){
        if(LOCAL){
            freopen("C:\\Users\\Smit Patel\\Desktop\\Questions\\This week\\input6.txt","r",stdin);
            freopen("C:\\Users\\Smit Patel\\Desktop\\Questions\\This week\\output6.txt","w",stdout);
        }

        v.pb(mp(mp(INT_MIN,INT_MIN),0));

        si2(n,k);
        FORi(1,n){
            si2(x,y);
            v.pb(mp(mp(x,y),i));
        }

        sort(all(v),myobject);

        set<pair<prii,int>> en,st;

        FORi(1,n){
            if(en.size()==k){
                lli a=(en.begin())->f.f;
                lli b=(st.rbegin())->f.f;
           //     debugs(b,a);
                if(a-b+1>ans){
                    ans=a-b+1;
                    id=st;
                }
            }

            int l=v[i].f.f,r=v[i].f.s,idx=v[i].s;
            while(st.size()>0 && en.begin()->f.f<r){
                auto p=*en.begin();
         //       debugs(i,p.s);
                en.erase(en.begin());
                st.erase(mp(mp(p.f.s,p.f.f),p.s));
            }

            st.insert(mp(mp(l,r),idx));
            en.insert(mp(mp(r,l),idx));

            if(en.size()==k){
                lli a=(en.begin())->f.f;
                lli b=(st.rbegin())->f.f;
                if(a-b+1>ans){
                    ans=a-b+1;
                    id=st;
                }
            }
        }

        if(ans==0){
            pi(ans);pn;
            FORi(1,k){pi(i);ps;}
        }
        else{
            pi(ans);pn;
            for(auto p:id){pi(p.s);ps;}
        }

        return 0;
    }


    #include<bits/stdc++.h>
    using namespace std;

    #define LOCAL 0

    #define length(a) (sizeof(a)/sizeof(a[0]))
    #define print(v,i,x) for(int j=i;j<=x;j++){cout<<v[j]<<" ";}cout<<endl;
    #define pb push_back
    #define mp make_pair
    #define lli long long int
    #define ulli unsigned long long int
    #define all(x) x.begin(),x.end()
    #define f first
    #define s second

    #define si(x) scanf("%d",&x);
    #define sli(x) scanf("%ld",&x);
    #define slli(x) scanf("%lld",&x);
    #define si2(x,y) {si(x);si(y);}
    #define si3(x,y,z) {si(x);si(y);si(z);}
    #define slli2(x,y) {slli(x);slli(y);}
    #define slli3(x,y,z) {slli(x);slli(y);slli(z);}

    #define pi(x) printf("%d",x);
    #define pi2(x,y) printf("%d %d",x,y);
    #define pi3(x,y,z) printf("%d %d %d",x,y,z);
    #define pli(x) printf("%ld",x);
    #define plli(x) printf("%lld",x);
    #define plli2(x,y) printf("%lld %lld",x,y);
    #define plli3(x,y,z) printf("%lld %lld %lld",x,y,z);
    #define pn printf("\n");
    #define ps printf(" ");
    #define pc(c) printf("%c",c);

    #define FOR(n) for(int i=0;i<n;i++)
    #define FORi(x,n) for(int i=x;i<=n;i++)
    #define FORj(x,n) for(int j=x;j<=n;j++)
    #define FORk(x,n) for(int k=x;k<=n;k++)
    #define ROFi(x,n) for(int i=x;i>=n;i--)
    #define ROFj(x,n) for(int j=x;j>=n;j--)
    #define ROFk(x,n) for(int k=x;k>=n;k--)

    #define debug(x) cout << "  - " << #x << ": " << x << endl;
    #define debugs(x, y) cout << "  - " << #x << ": " << x << "         " << #y << ": " << y << endl;
    #define debugss(x, y, z) cout << "  - " << #x << ": " << x << "         " << #y << ": " << y << "         " << #z << ": " << z <<  endl;
    #define fastIO 	std::ios::sync_with_stdio(false);cin.tie(NULL);

    typedef vector<int> vi;
    typedef vector<long> vli;
    typedef vector<long long> vlli;
    typedef vector<string> vstr;

    typedef pair<int,int> prii;
    typedef pair<int,lli> prilli;
    typedef pair<lli,int> prllii;
    typedef pair<lli,lli> prllilli;

    template <class T>T max3(T a,T b,T c){return max2(max2(a,b),c);}
    template <class T>T min3(T a,T b,T c){return min2(min2(a,b),c);}
    template <class T>T max4(T a,T b,T c,T d){return max2(max2(a,b),max2(c,d));}
    template <class T>T min4(T a,T b,T c,T d){return min2(min2(a,b),max2(c,d));}

    const lli mod = 1000000007ll;
    const lli MOD = 1000000009ll;
    const lli INF = LLONG_MAX/10;
    const int inf = INT_MAX/2;

    lli count_bit(lli _x){lli _ret=0;while(_x){if(_x%2==1)_ret++;_x/=2;}return _ret;}
    lli check_bit(lli _mask,lli _i){lli x=1;return (_mask&(x<<_i))==0?0:1;}
    lli set_bit(lli _mask,lli _i){lli x=1;_mask=_mask|(x<<_i);return _mask;}
    lli powermod(lli _a,lli _b,lli _m=mod){lli _r=1;while(_b){if(_b%2==1)_r=(_r*_a)%_m;_b/=2;_a=(_a*_a)%_m;}return _r;}
    lli power(lli _a,lli _b){lli _r=1;while(_b){if(_b%2==1)_r=(_r*_a);_b/=2;_a=(_a*_a);}return _r;}
    lli add(lli a,lli b,lli m=mod){lli x=a+b;while(x>=m)x-=m;return x;}
    lli sub(lli a,lli b,lli m=mod){lli x=a-b;while(x<0)x+=m;return x;}
    lli mul(lli a,lli b,lli m=mod){lli x=a*b;x%=m;return x;}
    lli gcd(lli a,lli b){ if(a<b) {a=a^b;b=a^b;a=a^b;} if(b==0)return a; lli t; while(b){t=b; b=a%b; a=t;}return a;}
    lli lcm(lli a,lli b){ return (a*b)/gcd(a,b); }

     vector<string> _split(const string& s, char c) {
        vector<string> v;
        stringstream ss(s);
        string x;
        while (getline(ss, x, c))
            v.emplace_back(x);
        return v;
    }

    //	int dx[]={-1,-1,0,1,1,1,0,-1};
    //	int dy[]={0,1,1,1,0,-1,-1,-1};

    //int dx[]={-1,0,1,0};
    //int dy[]={0,1,0,-1};

    /*
    bool prime[100010];
    void sieve(){
        fill(prime,prime+100010,true);
        prime[0]=prime[1]=false;

        for(lli i=2;i<100010;i++){
            if(prime[i]){
                for(lli j=i*i;j<100010;j+=i)
                {prime[j]=false;}
            }
        }
    }
*/
     prii operator +(const prii& l , const prii& r){
         prii ret;
         ret.f=l.f+r.f;
         ret.s=l.s+r.s;
         return ret;
     }

    struct cmp{
        bool operator()(pair<prii,int> const & l,pair<prii,int> const & r) {
            return (l.f.f!=r.f.f)?(l.f.f<r.f.f):(l.f.s<r.f.s);
        }
    }myobject;

    int n,k,l,r,x,y;
    vector<pair<prii,int>> v;
    lli ans=0;
    set<pair<prii,int>> id;

    int main(){
        if(LOCAL){
            freopen("C:\\Users\\Smit Patel\\Desktop\\Questions\\This week\\input6.txt","r",stdin);
            freopen("C:\\Users\\Smit Patel\\Desktop\\Questions\\This week\\output6.txt","w",stdout);
        }

        v.pb(mp(mp(INT_MIN,INT_MIN),0));

        si2(n,k);
        FORi(1,n){
            si2(x,y);
            v.pb(mp(mp(x,y),i));
        }

        sort(all(v),myobject);

        set<pair<prii,int>> en,st;

        FORi(1,n){
            if(en.size()==k){
                int a=(en.begin())->f.f;
                int b=(st.rbegin())->f.f;
                if(b-a+1>ans){
                    ans=b-a+1;
                    id=st;
                }
            }

            int l=v[i].f.f,r=v[i].f.s,idx=v[i].s;
            while(st.size()>0 && en.begin()->f.f<l){
                auto p=*en.begin();
                en.erase(en.begin());
                st.erase(mp(mp(p.f.s,p.f.f),p.s));
            }

            st.insert(mp(mp(l,r),idx));
            en.insert(mp(mp(r,l),idx));

            if(en.size()==k){
                int a=(en.begin())->f.f;
                int b=(st.rbegin())->f.f;
                if(b-a+1>ans){
                    ans=b-a+1;
                    id=st;
                }
            }
        }

        if(ans==0){
            pi(ans);pn;
            FORi(1,k){pi(i);ps;}
        }
        else{
            pi(ans);pn;
            for(auto p:id){pi(p.s);ps;}
        }

        return 0;
    }


    #include<bits/stdc++.h>
	#include<bits/stdc++.h>
	#include<bits/stdc++.h>
	using namespace std;

	#define length(a) (sizeof(a)/sizeof(a[0]))
	#define print(v,i,x) for(int j=i;j<=x;j++){cout<<v[j]<<" ";}cout<<endl;
	#define pb push_back
	#define mp make_pair
	#define lli long long int
	#define ulli unsigned long long int
	#define all(x) x.begin(),x.end()
	#define f first
	#define s second

	#define si(x) scanf("%d",&x);
	#define sli(x) scanf("%ld",&x);
	#define slli(x) scanf("%lld",&x);
	#define slu(x) scanf("%lu",&x);
	#define sllu(x) scanf("%llu",&x);
	#define si2(x,y) si(x);si(y);
	#define si3(x,y,z) si(x);si(y);si(z);
	#define slli2(x,y) slli(x);slli(y);
	#define slli3(x,y,z) slli(x);slli(y);slli(z);

	#define pi(x) printf("%d",x);
	#define pli(x) printf("%ld",x);
	#define plli(x) printf("%lld",x);
	#define plu(x) printf("%lu",x);
	#define pllu(x) printf("llu",x);
	#define pn printf("\n");
	#define ps printf(" ");
	#define pc(c) printf("%c",c);

	#define FOR(n) for(int i=0;i<n;i++)
	#define FORi(x,n) for(int i=x;i<=n;i++)
	#define FORj(x,n) for(int j=x;j<=n;j++)
	#define FORk(x,n) for(int k=x;k<=n;k++)
	#define ROFi(x,n) for(int i=x;i>=n;i--)
	#define ROFj(x,n) for(int j=x;j>=n;j--)
	#define ROFk(x,n) for(int k=x;k>=n;k--)

	#define debug(x) cout << "  - " << #x << ": " << x << endl;
	#define debugs(x, y) cout << "  - " << #x << ": " << x << "         " << #y << ": " << y << endl;
	#define fastIO 	std::ios::sync_with_stdio(false);cin.tie(NULL);

	typedef vector<int> vi;
	typedef vector<long> vli;
	typedef vector<long long> vlli;
	typedef vector<string> vstr;

	typedef pair<int,int> prii;
	typedef pair<long,int> prlii;
	typedef pair<int,long> prili;
	typedef pair<int,lli> prilli;
	typedef pair<lli,int> prllii;
	typedef pair<long,lli> prlilli;
	typedef pair<lli,long> prllili;
	typedef pair<lli,lli> prllilli;
	typedef pair<long,long> prlili;

	template <class T>T max2(T a,T b){return a<b?b:a;}
	template <class T>T min2(T a,T b){return a<b?a:b;}
	template <class T>T max3(T a,T b,T c){return max2(max2(a,b),c);}
	template <class T>T min3(T a,T b,T c){return min2(min2(a,b),c);}
	template <class T>T max4(T a,T b,T c,T d){return max2(max2(a,b),max2(c,d));}
	template <class T>T min4(T a,T b,T c,T d){return min2(min2(a,b),max2(c,d));}

	const lli mod = 1000000007ll;
	const lli MOD = 1000000009ll;

	lli bit_count(lli _x){lli _ret=0;while(_x){if(_x%2==1)_ret++;_x/=2;}return _ret;}
	lli bit(lli _mask,lli _i){lli x=1;return (_mask&(x<<_i))==0?0:1;}
	lli powermod(lli _a,lli _b,lli _m=mod){lli _r=1;while(_b){if(_b%2==1)_r=(_r*_a)%_m;_b/=2;_a=(_a*_a)%_m;}return _r;}
	lli power(lli _a,lli _b){lli _r=1;while(_b){if(_b%2==1)_r=(_r*_a);_b/=2;_a=(_a*_a);}return _r;}
	lli add(lli a,lli b,lli m=mod){lli x=a+b;while(x>=m)x-=m;return x;}
	lli sub(lli a,lli b,lli m=mod){lli x=a-b;while(x<0)x+=m;return x;}
	lli mul(lli a,lli b,lli m=mod){lli x=a*b;x%=m;return x;}
	lli gcd(lli a,lli b){ if(a<b) {a=a^b;b=a^b;a=a^b;} if(b==0)return a; lli t; while(b){t=b; b=a%b; a=t;}return a;}
	lli lcm(lli a,lli b){ return (a*b)/gcd(a,b); }

//	int dx[]={-1,-1,0,1,1,1,0,-1};
//	int dy[]={0,1,1,1,0,-1,-1,-1};

	/*
	vector<string> _split(const string& s, char c) {
		vector<string> v;
		stringstream ss(s);
		string x;
		while (getline(ss, x, c))
			v.emplace_back(x);
		return v;
	}
	*/
	 prii operator +(const prii& l , const prii& r){
		 prii ret;
		 ret.f=l.f+r.f;
		 ret.s=l.s+r.s;
		 return ret;
	 }

	struct cmp{
		bool operator()(pair<prllilli,int>  const & l,pair<prllilli,int>  const & r) {
			if(l.f.s!=r.f.s)
			return l.f.s<r.f.s;
			else
			return l.f.f<r.f.f;
		}
	}myobject;

	struct cmp1{
		bool operator()(pair<prllilli,int>  const & l,pair<prllilli,int>  const & r) {
			if(l.f.f!=r.f.f)
			return l.f.f<r.f.f;
			else
			return l.f.s>r.f.s;
		}
	}myobject1;

	int n,k;
	vector<pair<prllilli,int>> c,v;
    lli x,y,ans=0;
    vi f;
    set<pair<prllilli,int>,cmp> s;
    multiset<lli> st;

    bool check(lli m){
        s.clear();
        st.clear();

        FOR(v.size()){

 //          cout<<"-----------------------\n";
 //           debugs(i,s.size());
   //         for(auto p:s)
   //         cout<<p.f.f<<" "<<p.f.s<<"  "<<p.s<<endl;

            if(s.size()==k){
                lli l=*(--st.end());
                lli r=s.begin()->f.s;
      //           debugs(l,r);
                if(r-l+1>=m){
      //             debug(m);
                    f.clear();
                    for(auto p:s)
                    f.pb(p.s);

                    return true;
                }

                lli x=s.begin()->f.f;
                st.erase(st.find(x));
                s.erase(s.begin());

            }

            while(s.size()>0 && s.begin()->f.s < v[i].f.f){
                lli x=s.begin()->f.f;
                st.erase(st.find(x));
                s.erase(s.begin());
            }

            s.insert(mp(mp(v[i].f.f,v[i].f.s),v[i].s));
            st.insert(v[i].f.f);

        }

        return false;
    }

	int main(){

        si(n);si(k);

        FOR(n){
            slli(x);slli(y);
            c.pb(mp(mp(x,y),i+1));
        }

        c.pb(mp(mp(LLONG_MAX/2,LLONG_MAX/2),n+1));
        v=c;

        sort(all(v),myobject1);
      //  cout<<check(1);
        lli l=1,r=2000000010;

        while(r>=l){
            lli mid=l+(r-l)/2;

            if(check(mid)){
                ans=mid;
                l=mid+1;

            }
            else
            {r=mid-1;}

        }

        plli(ans);pn;
    //    debug(f.size());
        if(f.size()>0){
            sort(all(f));
            for(auto p:f)
            {pi(p);ps;}
        }
        else{
            FORi(1,k)
            {pi(i);ps;}
        }

		return 0;

	}


    #include<bits/stdc++.h>
	#include<bits/stdc++.h>
	#include<bits/stdc++.h>
	using namespace std;

	#define length(a) (sizeof(a)/sizeof(a[0]))
	#define print(v,i,x) for(int j=i;j<=x;j++){cout<<v[j]<<" ";}cout<<endl;
	#define pb push_back
	#define mp make_pair
	#define lli long long int
	#define ulli unsigned long long int
	#define all(x) x.begin(),x.end()
	#define f first
	#define s second

	#define si(x) scanf("%d",&x);
	#define sli(x) scanf("%ld",&x);
	#define slli(x) scanf("%lld",&x);
	#define slu(x) scanf("%lu",&x);
	#define sllu(x) scanf("%llu",&x);
	#define si2(x,y) si(x);si(y);
	#define si3(x,y,z) si(x);si(y);si(z);
	#define slli2(x,y) slli(x);slli(y);
	#define slli3(x,y,z) slli(x);slli(y);slli(z);

	#define pi(x) printf("%d",x);
	#define pli(x) printf("%ld",x);
	#define plli(x) printf("%lld",x);
	#define plu(x) printf("%lu",x);
	#define pllu(x) printf("llu",x);
	#define pn printf("\n");
	#define ps printf(" ");
	#define pc(c) printf("%c",c);

	#define FOR(n) for(int i=0;i<n;i++)
	#define FORi(x,n) for(int i=x;i<=n;i++)
	#define FORj(x,n) for(int j=x;j<=n;j++)
	#define FORk(x,n) for(int k=x;k<=n;k++)
	#define ROFi(x,n) for(int i=x;i>=n;i--)
	#define ROFj(x,n) for(int j=x;j>=n;j--)
	#define ROFk(x,n) for(int k=x;k>=n;k--)

	#define debug(x) cout << "  - " << #x << ": " << x << endl;
	#define debugs(x, y) cout << "  - " << #x << ": " << x << "         " << #y << ": " << y << endl;
	#define fastIO 	std::ios::sync_with_stdio(false);cin.tie(NULL);

	typedef vector<int> vi;
	typedef vector<long> vli;
	typedef vector<long long> vlli;
	typedef vector<string> vstr;

	typedef pair<int,int> prii;
	typedef pair<long,int> prlii;
	typedef pair<int,long> prili;
	typedef pair<int,lli> prilli;
	typedef pair<lli,int> prllii;
	typedef pair<long,lli> prlilli;
	typedef pair<lli,long> prllili;
	typedef pair<lli,lli> prllilli;
	typedef pair<long,long> prlili;

	template <class T>T max2(T a,T b){return a<b?b:a;}
	template <class T>T min2(T a,T b){return a<b?a:b;}
	template <class T>T max3(T a,T b,T c){return max2(max2(a,b),c);}
	template <class T>T min3(T a,T b,T c){return min2(min2(a,b),c);}
	template <class T>T max4(T a,T b,T c,T d){return max2(max2(a,b),max2(c,d));}
	template <class T>T min4(T a,T b,T c,T d){return min2(min2(a,b),max2(c,d));}

	const lli mod = 1000000007ll;
	const lli MOD = 1000000009ll;

	lli bit_count(lli _x){lli _ret=0;while(_x){if(_x%2==1)_ret++;_x/=2;}return _ret;}
	lli bit(lli _mask,lli _i){lli x=1;return (_mask&(x<<_i))==0?0:1;}
	lli powermod(lli _a,lli _b,lli _m=mod){lli _r=1;while(_b){if(_b%2==1)_r=(_r*_a)%_m;_b/=2;_a=(_a*_a)%_m;}return _r;}
	lli power(lli _a,lli _b){lli _r=1;while(_b){if(_b%2==1)_r=(_r*_a);_b/=2;_a=(_a*_a);}return _r;}
	lli add(lli a,lli b,lli m=mod){lli x=a+b;while(x>=m)x-=m;return x;}
	lli sub(lli a,lli b,lli m=mod){lli x=a-b;while(x<0)x+=m;return x;}
	lli mul(lli a,lli b,lli m=mod){lli x=a*b;x%=m;return x;}
	lli gcd(lli a,lli b){ if(a<b) {a=a^b;b=a^b;a=a^b;} if(b==0)return a; lli t; while(b){t=b; b=a%b; a=t;}return a;}
	lli lcm(lli a,lli b){ return (a*b)/gcd(a,b); }

//	int dx[]={-1,-1,0,1,1,1,0,-1};
//	int dy[]={0,1,1,1,0,-1,-1,-1};

	/*
	vector<string> _split(const string& s, char c) {
		vector<string> v;
		stringstream ss(s);
		string x;
		while (getline(ss, x, c))
			v.emplace_back(x);
		return v;
	}
	*/
	 prii operator +(const prii& l , const prii& r){
		 prii ret;
		 ret.f=l.f+r.f;
		 ret.s=l.s+r.s;
		 return ret;
	 }

	struct cmp{
		bool operator()(pair<prllilli,int>  const & l,pair<prllilli,int>  const & r) {
			if(l.f.s!=r.f.s)
			return l.f.s<r.f.s;
			else
			return l.f.f<r.f.f;
		}
	}myobject;

	struct cmp1{
		bool operator()(pair<prllilli,int>  const & l,pair<prllilli,int>  const & r) {
			if(l.f.f!=r.f.f)
			return l.f.f<r.f.f;
			else
			return l.f.s>r.f.s;
		}
	}myobject1;

	int n,k;
	vector<pair<prllilli,int>> c,v;
    lli x,y,ans=0;
    vi f;
    set<pair<prllilli,int>,cmp> s;
    multiset<lli> st;

    bool check(lli m){
        s.clear();
        st.clear();

        FOR(v.size()){

 //          cout<<"-----------------------\n";
 //           debugs(i,s.size());
   //         for(auto p:s)
   //         cout<<p.f.f<<" "<<p.f.s<<"  "<<p.s<<endl;

            if(s.size()==k){
                lli l=*(--st.end());
                lli r=s.begin()->f.s;
      //           debugs(l,r);
                if(r-l+1>=m){
      //             debug(m);
                    f.clear();
                    for(auto p:s)
                    f.pb(p.s);

                    return true;
                }

                lli x=s.begin()->f.f;
                st.erase(st.find(x));
                s.erase(s.begin());

            }

            while(s.size()>0 && s.begin()->f.s < v[i].f.f){
                lli x=s.begin()->f.f;
                st.erase(st.find(x));
                s.erase(s.begin());
            }

            s.insert(mp(mp(v[i].f.f,v[i].f.s),v[i].s));
            st.insert(v[i].f.f);

        }

        return false;
    }

	int main(){

        si(n);si(k);
        lli mn=LLONG_MIN,mx=LLONG_MAX;
        FOR(n){
            slli(x);slli(y);
            mn=min(mn,x);
            mx=max(mx,y);
            c.pb(mp(mp(x,y),i+1));
        }

        c.pb(mp(mp(LLONG_MAX/2,LLONG_MAX/2),n+1));
        v=c;

        sort(all(v),myobject1);
      //  cout<<check(1);
        lli l=1,r=200000010;

        while(r>=l){
            lli mid=l+(r-l)/2;

            if(check(mid)){
                ans=mid;
                l=mid+1;

            }
            else
            {r=mid-1;}

        }

        plli(ans);pn;
    //    debug(f.size());
        if(f.size()>0){
            sort(all(f));
            for(auto p:f)
            {pi(p);ps;}
        }
        else{
            FORi(1,k)
            {pi(i);ps;}
        }

		return 0;

	}


    #include<bits/stdc++.h>
    using namespace std;

    #define LOCAL 0

    #define length(a) (sizeof(a)/sizeof(a[0]))
    #define print(v,i,x) for(int j=i;j<=x;j++){cout<<v[j]<<" ";}cout<<endl;
    #define pb push_back
    #define mp make_pair
    #define lli long long int
    #define ulli unsigned long long int
    #define all(x) x.begin(),x.end()
    #define f first
    #define s second

    #define si(x) scanf("%d",&x);
    #define sli(x) scanf("%ld",&x);
    #define slli(x) scanf("%lld",&x);
    #define si2(x,y) {si(x);si(y);}
    #define si3(x,y,z) {si(x);si(y);si(z);}
    #define slli2(x,y) {slli(x);slli(y);}
    #define slli3(x,y,z) {slli(x);slli(y);slli(z);}

    #define pi(x) printf("%d",x);
    #define pi2(x,y) printf("%d %d",x,y);
    #define pi3(x,y,z) printf("%d %d %d",x,y,z);
    #define pli(x) printf("%ld",x);
    #define plli(x) printf("%lld",x);
    #define plli2(x,y) printf("%lld %lld",x,y);
    #define plli3(x,y,z) printf("%lld %lld %lld",x,y,z);
    #define pn printf("\n");
    #define ps printf(" ");
    #define pc(c) printf("%c",c);

    #define FOR(n) for(int i=0;i<n;i++)
    #define FORi(x,n) for(int i=x;i<=n;i++)
    #define FORj(x,n) for(int j=x;j<=n;j++)
    #define FORk(x,n) for(int k=x;k<=n;k++)
    #define ROFi(x,n) for(int i=x;i>=n;i--)
    #define ROFj(x,n) for(int j=x;j>=n;j--)
    #define ROFk(x,n) for(int k=x;k>=n;k--)

    #define debug(x) cout << "  - " << #x << ": " << x << endl;
    #define debugs(x, y) cout << "  - " << #x << ": " << x << "         " << #y << ": " << y << endl;
    #define debugss(x, y, z) cout << "  - " << #x << ": " << x << "         " << #y << ": " << y << "         " << #z << ": " << z <<  endl;
    #define fastIO 	std::ios::sync_with_stdio(false);cin.tie(NULL);

    typedef vector<int> vi;
    typedef vector<long> vli;
    typedef vector<long long> vlli;
    typedef vector<string> vstr;

    typedef pair<int,int> prii;
    typedef pair<int,lli> prilli;
    typedef pair<lli,int> prllii;
    typedef pair<lli,lli> prllilli;

    template <class T>T max3(T a,T b,T c){return max2(max2(a,b),c);}
    template <class T>T min3(T a,T b,T c){return min2(min2(a,b),c);}
    template <class T>T max4(T a,T b,T c,T d){return max2(max2(a,b),max2(c,d));}
    template <class T>T min4(T a,T b,T c,T d){return min2(min2(a,b),max2(c,d));}

    const lli mod = 1000000007ll;
    const lli MOD = 1000000009ll;
    const lli INF = LLONG_MAX/10;
    const int inf = INT_MAX/2;

    lli count_bit(lli _x){lli _ret=0;while(_x){if(_x%2==1)_ret++;_x/=2;}return _ret;}
    lli check_bit(lli _mask,lli _i){lli x=1;return (_mask&(x<<_i))==0?0:1;}
    lli set_bit(lli _mask,lli _i){lli x=1;_mask=_mask|(x<<_i);return _mask;}
    lli powermod(lli _a,lli _b,lli _m=mod){lli _r=1;while(_b){if(_b%2==1)_r=(_r*_a)%_m;_b/=2;_a=(_a*_a)%_m;}return _r;}
    lli power(lli _a,lli _b){lli _r=1;while(_b){if(_b%2==1)_r=(_r*_a);_b/=2;_a=(_a*_a);}return _r;}
    lli add(lli a,lli b,lli m=mod){lli x=a+b;while(x>=m)x-=m;return x;}
    lli sub(lli a,lli b,lli m=mod){lli x=a-b;while(x<0)x+=m;return x;}
    lli mul(lli a,lli b,lli m=mod){lli x=a*b;x%=m;return x;}
    lli gcd(lli a,lli b){ if(a<b) {a=a^b;b=a^b;a=a^b;} if(b==0)return a; lli t; while(b){t=b; b=a%b; a=t;}return a;}
    lli lcm(lli a,lli b){ return (a*b)/gcd(a,b); }

     vector<string> _split(const string& s, char c) {
        vector<string> v;
        stringstream ss(s);
        string x;
        while (getline(ss, x, c))
            v.emplace_back(x);
        return v;
    }

    //	int dx[]={-1,-1,0,1,1,1,0,-1};
    //	int dy[]={0,1,1,1,0,-1,-1,-1};

    //int dx[]={-1,0,1,0};
    //int dy[]={0,1,0,-1};

    /*
    bool prime[100010];
    void sieve(){
        fill(prime,prime+100010,true);
        prime[0]=prime[1]=false;

        for(lli i=2;i<100010;i++){
            if(prime[i]){
                for(lli j=i*i;j<100010;j+=i)
                {prime[j]=false;}
            }
        }
    }
*/
     prii operator +(const prii& l , const prii& r){
         prii ret;
         ret.f=l.f+r.f;
         ret.s=l.s+r.s;
         return ret;
     }

    struct cmp{
        bool operator()(pair<prii,int> const & l,pair<prii,int> const & r) {
            return (l.f.f!=r.f.f)?(l.f.f<r.f.f):(l.f.s<r.f.s);
        }
    }myobject;

    int n,k,l,r,x,y;
    vector<pair<prii,int>> v;
    lli ans=0;
    set<pair<prii,int>> id;

    int main(){
        if(LOCAL){
            freopen("C:\\Users\\Smit Patel\\Desktop\\Questions\\This week\\input6.txt","r",stdin);
            freopen("C:\\Users\\Smit Patel\\Desktop\\Questions\\This week\\output6.txt","w",stdout);
        }

        v.pb(mp(mp(INT_MIN,INT_MIN),0));

        si2(n,k);
        FORi(1,n){
            si2(x,y);
            v.pb(mp(mp(x,y),i));
        }

        sort(all(v),myobject);

        set<pair<prii,int>> en,st;

        FORi(1,n){
            if(en.size()==k){
                lli a=(en.begin())->f.f;
                lli b=(st.rbegin())->f.f;
           //     debugs(b,a);
                if(a-b+1>ans){
                    ans=a-b+1;
                    id=st;
                }
            }

            int l=v[i].f.f,r=v[i].f.s,idx=v[i].s;
            if(st.size()>0 && en.begin()->f.f<l){
                auto p=*en.begin();
                en.erase(en.begin());
                st.erase(mp(mp(p.f.s,p.f.f),p.s));
            }

            st.insert(mp(mp(l,r),idx));
            en.insert(mp(mp(r,l),idx));

            if(en.size()==k){
                lli a=(en.begin())->f.f;
                lli b=(st.rbegin())->f.f;
                if(a-b+1>ans){
                    ans=a-b+1;
                    id=st;
                }
            }
        }

        if(ans==0){
            pi(ans);pn;
            FORi(1,k){pi(i);ps;}
        }
        else{
            pi(ans);pn;
            for(auto p:id){pi(p.s);ps;}
        }

        return 0;
    }


   #include<bits/stdc++.h>
	#include<bits/stdc++.h>
	#include<bits/stdc++.h>
	using namespace std;

	#define length(a) (sizeof(a)/sizeof(a[0]))
	#define print(v,i,x) for(int j=i;j<=x;j++){cout<<v[j]<<" ";}cout<<endl;
	#define pb push_back
	#define mp make_pair
	#define lli long long int
	#define ulli unsigned long long int
	#define all(x) x.begin(),x.end()
	#define f first
	#define s second

	#define si(x) scanf("%d",&x);
	#define sli(x) scanf("%ld",&x);
	#define slli(x) scanf("%lld",&x);
	#define slu(x) scanf("%lu",&x);
	#define sllu(x) scanf("%llu",&x);
	#define si2(x,y) si(x);si(y);
	#define si3(x,y,z) si(x);si(y);si(z);
	#define slli2(x,y) slli(x);slli(y);
	#define slli3(x,y,z) slli(x);slli(y);slli(z);

	#define pi(x) printf("%d",x);
	#define pli(x) printf("%ld",x);
	#define plli(x) printf("%lld",x);
	#define plu(x) printf("%lu",x);
	#define pllu(x) printf("llu",x);
	#define pn printf("\n");
	#define ps printf(" ");
	#define pc(c) printf("%c",c);

	#define FOR(n) for(int i=0;i<n;i++)
	#define FORi(x,n) for(int i=x;i<=n;i++)
	#define FORj(x,n) for(int j=x;j<=n;j++)
	#define FORk(x,n) for(int k=x;k<=n;k++)
	#define ROFi(x,n) for(int i=x;i>=n;i--)
	#define ROFj(x,n) for(int j=x;j>=n;j--)
	#define ROFk(x,n) for(int k=x;k>=n;k--)

	#define debug(x) cout << "  - " << #x << ": " << x << endl;
	#define debugs(x, y) cout << "  - " << #x << ": " << x << "         " << #y << ": " << y << endl;
	#define fastIO 	std::ios::sync_with_stdio(false);cin.tie(NULL);

	typedef vector<int> vi;
	typedef vector<long> vli;
	typedef vector<long long> vlli;
	typedef vector<string> vstr;

	typedef pair<int,int> prii;
	typedef pair<long,int> prlii;
	typedef pair<int,long> prili;
	typedef pair<int,lli> prilli;
	typedef pair<lli,int> prllii;
	typedef pair<long,lli> prlilli;
	typedef pair<lli,long> prllili;
	typedef pair<lli,lli> prllilli;
	typedef pair<long,long> prlili;

	template <class T>T max2(T a,T b){return a<b?b:a;}
	template <class T>T min2(T a,T b){return a<b?a:b;}
	template <class T>T max3(T a,T b,T c){return max2(max2(a,b),c);}
	template <class T>T min3(T a,T b,T c){return min2(min2(a,b),c);}
	template <class T>T max4(T a,T b,T c,T d){return max2(max2(a,b),max2(c,d));}
	template <class T>T min4(T a,T b,T c,T d){return min2(min2(a,b),max2(c,d));}

	const lli mod = 1000000007ll;
	const lli MOD = 1000000009ll;

	lli bit_count(lli _x){lli _ret=0;while(_x){if(_x%2==1)_ret++;_x/=2;}return _ret;}
	lli bit(lli _mask,lli _i){lli x=1;return (_mask&(x<<_i))==0?0:1;}
	lli powermod(lli _a,lli _b,lli _m=mod){lli _r=1;while(_b){if(_b%2==1)_r=(_r*_a)%_m;_b/=2;_a=(_a*_a)%_m;}return _r;}
	lli power(lli _a,lli _b){lli _r=1;while(_b){if(_b%2==1)_r=(_r*_a);_b/=2;_a=(_a*_a);}return _r;}
	lli add(lli a,lli b,lli m=mod){lli x=a+b;while(x>=m)x-=m;return x;}
	lli sub(lli a,lli b,lli m=mod){lli x=a-b;while(x<0)x+=m;return x;}
	lli mul(lli a,lli b,lli m=mod){lli x=a*b;x%=m;return x;}
	lli gcd(lli a,lli b){ if(a<b) {a=a^b;b=a^b;a=a^b;} if(b==0)return a; lli t; while(b){t=b; b=a%b; a=t;}return a;}
	lli lcm(lli a,lli b){ return (a*b)/gcd(a,b); }

//	int dx[]={-1,-1,0,1,1,1,0,-1};
//	int dy[]={0,1,1,1,0,-1,-1,-1};

	/*
	vector<string> _split(const string& s, char c) {
		vector<string> v;
		stringstream ss(s);
		string x;
		while (getline(ss, x, c))
			v.emplace_back(x);
		return v;
	}
	*/
	 prii operator +(const prii& l , const prii& r){
		 prii ret;
		 ret.f=l.f+r.f;
		 ret.s=l.s+r.s;
		 return ret;
	 }

	struct cmp{
		bool operator()(pair<prllilli,int>  const & l,pair<prllilli,int>  const & r) {
			if(l.f.s!=r.f.s)
			return l.f.s<r.f.s;
			else
			return l.f.f<r.f.f;
		}
	}myobject;

	int n,k;
	vector<pair<prllilli,int>> c,v;
    lli x,y,ans=0;
    vi f;
    multiset<pair<prllilli,int>,cmp> s;
    multiset<lli> st;

    void check(){
        s.clear();
        st.clear();

        FOR(v.size()){

            if(s.size()==k){
                lli l=*(--st.end());
                lli r=s.begin()->f.s;
                if(r-l+1>=ans){
                    f.clear();
                    int cnt=0;
                    for(auto p:s)
                    {f.pb(p.s);}
                    ans=max(ans,r-l+1);
                }

             /*   lli x=s.begin()->f.f;
                st.erase(st.find(x));
                s.erase(s.begin());
                */
            }

            while(s.size()>0 && s.begin()->f.s < v[i].f.f){
                lli x=s.begin()->f.f;
                st.erase(st.find(x));
                s.erase(s.begin());
            }

            if(s.size()<k){
                s.insert(v[i]);
            st.insert(v[i].f.f);

            }

        }

    }

	int main(){

        si(n);si(k);
        lli mn=LLONG_MIN,mx=LLONG_MAX;
        FOR(n){
            slli(x);slli(y);
            mn=min(mn,x);
            mx=max(mx,y);
            c.pb(mp(mp(x,y),i+1));
        }

        c.pb(mp(mp(LLONG_MAX/2,LLONG_MAX/2),n+1));
        v=c;

        sort(all(v));

        lli l=1,r=200000010;

        check();
        plli(ans);pn;

        if(f.size()>0){
            sort(all(f));
            for(auto p:f)
            {pi(p);ps;}
        }
        else{
            FORi(1,k)
            {pi(i);ps;}
        }

		return 0;

	}


    #include<bits/stdc++.h>
    using namespace std;

    #define LOCAL 0

    #define length(a) (sizeof(a)/sizeof(a[0]))
    #define print(v,i,x) for(int j=i;j<=x;j++){cout<<v[j]<<" ";}cout<<endl;
    #define pb push_back
    #define mp make_pair
    #define lli long long int
    #define ulli unsigned long long int
    #define all(x) x.begin(),x.end()
    #define f first
    #define s second

    #define si(x) scanf("%d",&x);
    #define sli(x) scanf("%ld",&x);
    #define slli(x) scanf("%lld",&x);
    #define si2(x,y) {si(x);si(y);}
    #define si3(x,y,z) {si(x);si(y);si(z);}
    #define slli2(x,y) {slli(x);slli(y);}
    #define slli3(x,y,z) {slli(x);slli(y);slli(z);}

    #define pi(x) printf("%d",x);
    #define pi2(x,y) printf("%d %d",x,y);
    #define pi3(x,y,z) printf("%d %d %d",x,y,z);
    #define pli(x) printf("%ld",x);
    #define plli(x) printf("%lld",x);
    #define plli2(x,y) printf("%lld %lld",x,y);
    #define plli3(x,y,z) printf("%lld %lld %lld",x,y,z);
    #define pn printf("\n");
    #define ps printf(" ");
    #define pc(c) printf("%c",c);

    #define FOR(n) for(int i=0;i<n;i++)
    #define FORi(x,n) for(int i=x;i<=n;i++)
    #define FORj(x,n) for(int j=x;j<=n;j++)
    #define FORk(x,n) for(int k=x;k<=n;k++)
    #define ROFi(x,n) for(int i=x;i>=n;i--)
    #define ROFj(x,n) for(int j=x;j>=n;j--)
    #define ROFk(x,n) for(int k=x;k>=n;k--)

    #define debug(x) cout << "  - " << #x << ": " << x << endl;
    #define debugs(x, y) cout << "  - " << #x << ": " << x << "         " << #y << ": " << y << endl;
    #define debugss(x, y, z) cout << "  - " << #x << ": " << x << "         " << #y << ": " << y << "         " << #z << ": " << z <<  endl;
    #define fastIO 	std::ios::sync_with_stdio(false);cin.tie(NULL);

    typedef vector<int> vi;
    typedef vector<long> vli;
    typedef vector<long long> vlli;
    typedef vector<string> vstr;

    typedef pair<int,int> prii;
    typedef pair<int,lli> prilli;
    typedef pair<lli,int> prllii;
    typedef pair<lli,lli> prllilli;

    template <class T>T max3(T a,T b,T c){return max2(max2(a,b),c);}
    template <class T>T min3(T a,T b,T c){return min2(min2(a,b),c);}
    template <class T>T max4(T a,T b,T c,T d){return max2(max2(a,b),max2(c,d));}
    template <class T>T min4(T a,T b,T c,T d){return min2(min2(a,b),max2(c,d));}

    const lli mod = 1000000007ll;
    const lli MOD = 1000000009ll;
    const lli INF = LLONG_MAX/10;
    const int inf = INT_MAX/2;

    lli count_bit(lli _x){lli _ret=0;while(_x){if(_x%2==1)_ret++;_x/=2;}return _ret;}
    lli check_bit(lli _mask,lli _i){lli x=1;return (_mask&(x<<_i))==0?0:1;}
    lli set_bit(lli _mask,lli _i){lli x=1;_mask=_mask|(x<<_i);return _mask;}
    lli powermod(lli _a,lli _b,lli _m=mod){lli _r=1;while(_b){if(_b%2==1)_r=(_r*_a)%_m;_b/=2;_a=(_a*_a)%_m;}return _r;}
    lli power(lli _a,lli _b){lli _r=1;while(_b){if(_b%2==1)_r=(_r*_a);_b/=2;_a=(_a*_a);}return _r;}
    lli add(lli a,lli b,lli m=mod){lli x=a+b;while(x>=m)x-=m;return x;}
    lli sub(lli a,lli b,lli m=mod){lli x=a-b;while(x<0)x+=m;return x;}
    lli mul(lli a,lli b,lli m=mod){lli x=a*b;x%=m;return x;}
    lli gcd(lli a,lli b){ if(a<b) {a=a^b;b=a^b;a=a^b;} if(b==0)return a; lli t; while(b){t=b; b=a%b; a=t;}return a;}
    lli lcm(lli a,lli b){ return (a*b)/gcd(a,b); }

     vector<string> _split(const string& s, char c) {
        vector<string> v;
        stringstream ss(s);
        string x;
        while (getline(ss, x, c))
            v.emplace_back(x);
        return v;
    }

    //	int dx[]={-1,-1,0,1,1,1,0,-1};
    //	int dy[]={0,1,1,1,0,-1,-1,-1};

    //int dx[]={-1,0,1,0};
    //int dy[]={0,1,0,-1};

    /*
    bool prime[100010];
    void sieve(){
        fill(prime,prime+100010,true);
        prime[0]=prime[1]=false;

        for(lli i=2;i<100010;i++){
            if(prime[i]){
                for(lli j=i*i;j<100010;j+=i)
                {prime[j]=false;}
            }
        }
    }
*/
     prii operator +(const prii& l , const prii& r){
         prii ret;
         ret.f=l.f+r.f;
         ret.s=l.s+r.s;
         return ret;
     }

    struct cmp{
        bool operator()(pair<prii,int> const & l,pair<prii,int> const & r) {
            return (l.f.f!=r.f.f)?(l.f.f<r.f.f):(l.f.s<r.f.s);
        }
    }myobject;

    int n,k,l,r,x,y;
    vector<pair<prii,int>> v;
    lli ans=0;
    set<pair<prii,int>> id;

    int main(){
        if(LOCAL){
            freopen("C:\\Users\\Smit Patel\\Desktop\\Questions\\This week\\input6.txt","r",stdin);
            freopen("C:\\Users\\Smit Patel\\Desktop\\Questions\\This week\\output6.txt","w",stdout);
        }

        v.pb(mp(mp(INT_MIN,INT_MIN),0));

        si2(n,k);
        FORi(1,n){
            si2(x,y);
            v.pb(mp(mp(x,y),i));
        }

        sort(all(v),myobject);

        set<pair<prii,int>> en,st;

        FORi(1,k){
            int l=v[i].f.f,r=v[i].f.s,idx=v[i].s;
            st.insert(mp(mp(l,r),idx));
            en.insert(mp(mp(r,l),idx));
        }

        if(en.size()==k){
                lli a=(en.begin())->f.f;
                lli b=(st.rbegin())->f.f;
           //     debugs(b,a);
                if(a-b+1>ans){
                    ans=a-b+1;
                    id=st;
                }
            }

        FORi(k+1,n){
            int l=v[i].f.f,r=v[i].f.s,idx=v[i].s;
            if(st.size()>0 && en.begin()->f.f<r){
                auto p=*en.begin();
                en.erase(en.begin());
                st.erase(mp(mp(p.f.s,p.f.f),p.s));
                st.insert(mp(mp(l,r),idx));
                en.insert(mp(mp(r,l),idx));
            }

            if(en.size()==k){
                lli a=(en.begin())->f.f;
                lli b=(st.rbegin())->f.f;
                if(a-b+1>ans){
                    ans=a-b+1;
                    id=st;
                }
            }
        }

        if(ans==0){
            pi(ans);pn;
            FORi(1,k){pi(i);ps;}
        }
        else{
            pi(ans);pn;
            for(auto p:id){pi(p.s);ps;}
        }

        return 0;
    }


#include <bits/stdc++.h>
#define LL long long
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
using namespace std;

typedef pair<int,int> ii;
int n,k,cnt,mx,x,y;
ii a[300100],b[300100];
queue<ii> q;

bool cmp(ii x, ii y){
	return x.sc<y.sc;
}

int main() {
	scanf("%d %d",&n,&k);
	for(int i=0;i<n;i++){
		scanf("%d %d",&a[i].fi,&a[i].sc);
		b[i].fi = a[i].sc;
		b[i].sc = i;
	}
	sort(b,b+n);
	for(int i=0;i<n;i++){
		q.push(mp(b[i].fi,b[i].sc));
	}
	sort(a,a+n);
	set<int> st,ans;
	for(int i=0;i<n;i++){
		while(!q.empty()){
			x = q.front().fi;
			y = q.front().sc;
			if(a[i].fi>x){
				cnt--;
				st.erase(y);
				q.pop();
			}
			else break;
		}
		st.insert(i);
		cnt++;
		// cout<<x<<" B "<<y<<endl;
		// cout<<a[i].fi<<"A "<<cnt<<endl;
		// for(set<int>::iterator it = st.begin();it!=st.end();it++){
		// 	cout<<(*it)<<" ";
		// }cout<<endl;
		int nxt = q.front().fi;
		if(cnt==k && nxt-a[i].fi+1>mx){
			mx = nxt-a[i].fi+1;
			ans = st;
		}
	}
	while(!q.empty()){
		x = q.front().fi;
		y = q.front().sc;
		set<int>::iterator it = st.end();
		it--;

		cnt--;
		st.erase(y);
		// cout<<x<<" B "<<y<<endl;
		// cout<<a[(*it)].fi<<"A "<<cnt<<endl;
		// for(set<int>::iterator it = st.begin();it!=st.end();it++){
		// 	cout<<(*it)<<" ";
		// }cout<<endl;
		int nxt = q.front().fi;
		if(cnt==k && nxt-a[(*it)].fi+1>mx){
			mx = nxt-a[(*it)].fi+1;
			ans = st;
		}
		q.pop();

	}
	cout<<mx<<endl;
	if(mx==0){
		for(int i=0;i<k;i++){
			ans.insert(i);
		}
	}
	for(set<int>::iterator it = ans.begin();it!=ans.end();it++){
		cout<<(*it)+1<<" ";
	}cout<<endl;
	return 0;
}


#include <bits/stdc++.h>
#define LL long long
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
using namespace std;

typedef pair<int,int> ii;
int n,k,cnt,mx,x,y;
ii a[300100],b[300100];
queue<ii> q;

bool cmp(ii x, ii y){
	return x.sc<y.sc;
}

int main() {
	scanf("%d %d",&n,&k);
	for(int i=0;i<n;i++){
		scanf("%d %d",&a[i].fi,&a[i].sc);
		b[i].fi = a[i].sc;
		b[i].sc = i;
	}
	sort(b,b+n);
	for(int i=0;i<n;i++){
		q.push(mp(b[i].fi,b[i].sc));
	}
	sort(a,a+n);
	set<int> st,ans;
	for(int i=0;i<n;i++){
		while(!q.empty()){
			x = q.front().fi;
			y = q.front().sc;
			if(a[i].fi>x){
				cnt--;
				st.erase(y);
				q.pop();
			}
			else break;
		}
		st.insert(i);
		cnt++;
		// cout<<x<<" B "<<y<<endl;
		cout<<a[i].fi<<"A "<<cnt<<endl;
		for(set<int>::iterator it = st.begin();it!=st.end();it++){
			cout<<(*it)<<" ";
		}cout<<endl;
		int nxt = q.front().fi;
		if(cnt==k && nxt-a[i].fi+1>mx){
			mx = nxt-a[i].fi+1;
			ans = st;
		}
	}
	while(!q.empty()){
		x = q.front().fi;
		y = q.front().sc;
		set<int>::iterator it = st.end();
		it--;

		cnt--;
		st.erase(y);
		// cout<<x<<" B "<<y<<endl;
		// cout<<a[(*it)].fi<<"A "<<cnt<<endl;
		// for(set<int>::iterator it = st.begin();it!=st.end();it++){
		// 	cout<<(*it)<<" ";
		// }cout<<endl;
		int nxt = q.front().fi;
		if(cnt==k && nxt-a[(*it)].fi+1>mx){
			mx = nxt-a[(*it)].fi+1;
			ans = st;
		}
		q.pop();

	}
	cout<<mx<<endl;
	if(mx==0){
		for(int i=0;i<k;i++){
			ans.insert(i);
		}
	}
	for(set<int>::iterator it = ans.begin();it!=ans.end();it++){
		cout<<(*it)+1<<" ";
	}cout<<endl;
	return 0;
}


#include <bits/stdc++.h>
#define LL long long
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
using namespace std;

typedef pair<int,int> ii;
int n,k,cnt,mx,x,y;
ii a[300100],b[300100];
queue<ii> q;

bool cmp(ii x, ii y){
	return x.sc<y.sc;
}

int main() {
	scanf("%d %d",&n,&k);
	for(int i=0;i<n;i++){
		scanf("%d %d",&a[i].fi,&a[i].sc);
		b[i].fi = a[i].sc;
		b[i].sc = i;
	}
	sort(b,b+n);
	for(int i=0;i<n;i++){
		q.push(mp(b[i].fi,b[i].sc));
	}
	sort(a,a+n);
	set<int> st,ans;
	for(int i=0;i<n;i++){
		while(!q.empty()){
			x = q.front().fi;
			y = q.front().sc;
			if(a[i].fi>x){
				cnt--;
				st.erase(y);
				q.pop();
			}
			else break;
		}
		st.insert(i);
		cnt++;
		// cout<<x<<" B "<<y<<endl;
		cout<<a[i].fi<<"A "<<cnt<<endl;
		for(set<int>::iterator it = st.begin();it!=st.end();it++){
			cout<<(*it)<<" ";
		}cout<<endl;
		int nxt = q.front().fi;
		if(cnt=k && nxt-a[i].fi+1>mx){
			mx = nxt-a[i].fi+1;
			ans = st;
		}
	}
	while(!q.empty()){
		x = q.front().fi;
		y = q.front().sc;
		set<int>::iterator it = st.end();
		it--;

		cnt--;
		st.erase(y);
		// cout<<x<<" B "<<y<<endl;
		// cout<<a[(*it)].fi<<"A "<<cnt<<endl;
		// for(set<int>::iterator it = st.begin();it!=st.end();it++){
		// 	cout<<(*it)<<" ";
		// }cout<<endl;
		int nxt = q.front().fi;
		if(cnt==k && nxt-a[(*it)].fi+1>mx){
			mx = nxt-a[(*it)].fi+1;
			ans = st;
		}
		q.pop();

	}
	cout<<mx<<endl;
	if(mx==0){
		for(int i=0;i<k;i++){
			ans.insert(i);
		}
	}
	for(set<int>::iterator it = ans.begin();it!=ans.end();it++){
		cout<<(*it)+1<<" ";
	}cout<<endl;
	return 0;
}


#include <bits/stdc++.h>
#define LL long long
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
using namespace std;

typedef pair<int,int> ii;
int n,k,cnt,mx,x,y;
ii a[300100];
queue<ii> q;

bool cmp(ii x, ii y){
	return x.sc<y.sc;
}

int main() {
	scanf("%d %d",&n,&k);
	for(int i=0;i<n;i++){
		scanf("%d %d",&a[i].fi,&a[i].sc);
	}
	sort(a,a+n,cmp);
	for(int i=0;i<n;i++){
		q.push(mp(a[i].sc,i));
	}
	sort(a,a+n);
	set<int> st,ans;
	for(int i=0;i<n;i++){
		while(!q.empty()){
			x = q.front().fi;
			y = q.front().sc;
			if(a[i].fi>x){
				cnt--;
				st.erase(y);
				q.pop();
			}
			else break;
		}
		st.insert(i);
		cnt++;
		// cout<<a[i].fi<<"A "<<cnt<<endl;
		// for(set<int>::iterator it = st.begin();it!=st.end();it++){
		// 	cout<<(*it)<<" ";
		// }cout<<endl;
		int nxt = q.front().fi;
		if(cnt==k && nxt-a[i].fi+1>mx){
			mx = nxt-a[i].fi+1;
			ans = st;
		}
	}
	cout<<mx<<endl;
	if(mx==0){
		for(int i=0;i<k;i++){
			ans.insert(i);
		}
	}
	for(set<int>::iterator it = ans.begin();it!=ans.end();it++){
		cout<<(*it)+1<<" ";
	}cout<<endl;
	return 0;
}


#include <bits/stdc++.h>
#define LL long long
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
using namespace std;

typedef pair<LL,LL> ii;
typedef pair<LL,ii> iii;

LL n,k,ans,temp;
iii a[300100];

int main() {
	set<ii> st;
	scanf("%lld %lld",&n,&k);
	for(int i=0;i<n;i++) scanf("%lld %lld",&a[i].fi, &a[i].sc.fi), a[i].sc.sc = i+1;
	sort(a, a+n);
	for(int i=0;i<n;i++){
		if(i>=k-1){
			ans = max(ans, min(a[i].sc.fi, st.begin()->fi) - a[i].fi + 1);
			st.erase(st.begin());
		}
		st.insert(mp(a[i].sc.fi, a[i].sc.sc));
//		cout<<a[i].fi<<" "<<a[i].sc<<" "<<st.begin()->fi<<" "<<ans<<endl;
	}
	st.clear();
	if(ans==0){
		cout<<ans<<endl;
		for(int i=0;i<k;i++){
			cout<<a[i].sc.sc<<" ";
		}
		return 0;
	}
	for(int i=0;i<n;i++){
		if(i>=k-1){
			temp = min(a[i].sc.fi, st.begin()->fi) - a[i].fi + 1;
			if(temp == ans){
				cout<<ans<<endl;
				k--;
				while(k--){
					cout<<st.begin()->sc<<" ";
					st.erase(st.begin());
				}
				cout<<a[i].sc.sc<<endl;
				return 0;
			}
			st.erase(st.begin());
		}
		st.insert(mp(a[i].sc.fi, a[i].sc.sc));
	}
	return 0;
}


#include <bits/stdc++.h>
#define LL long long
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
using namespace std;

typedef pair<int,int> ii;
int n,k,cnt,mx,x,y;
ii a[300100],b[300100];
queue<ii> q;

bool cmp(ii x, ii y){
	return x.sc<y.sc;
}

int main() {
	scanf("%d %d",&n,&k);
	for(int i=0;i<n;i++){
		scanf("%d %d",&a[i].fi,&a[i].sc);
		b[i].fi = a[i].sc;
		b[i].sc = i;
	}
	sort(b,b+n,cmp);
	for(int i=0;i<n;i++){
		q.push(mp(b[i].fi,b[i].sc));
	}
	sort(a,a+n);
	set<int> st,ans;
	for(int i=0;i<n;i++){
		while(!q.empty()){
			x = q.front().fi;
			y = q.front().sc;
			if(a[i].fi>x){
				cnt--;
				st.erase(y);
				q.pop();
			}
			else break;
		}
		st.insert(i);
		cnt++;
		// cout<<a[i].fi<<"A "<<cnt<<endl;
		// for(set<int>::iterator it = st.begin();it!=st.end();it++){
		// 	cout<<(*it)<<" ";
		// }cout<<endl;
		int nxt = q.front().fi;
		if(cnt>=k && nxt-a[i].fi+1>mx){
			mx = nxt-a[i].fi+1;
			ans = st;
		}
	}
	while(!q.empty()){
		x = q.front().fi;
		y = q.front().sc;
		set<int>::iterator it = st.end();
		it--;
		// cout<<x<<" B "<<y<<endl;
		// cout<<a[(*it)].fi<<"A "<<cnt<<endl;
		// for(set<int>::iterator it = st.begin();it!=st.end();it++){
		// 	cout<<(*it)<<" ";
		// }cout<<endl;
		int nxt = q.front().fi;
		if(cnt>=k && nxt-a[(*it)].fi+1>mx){
			mx = nxt-a[(*it)].fi+1;
			ans = st;
		}
		cnt--;
		st.erase(y);
		q.pop();

	}
	cout<<mx<<endl;
	if(mx==0){
		for(int i=0;i<k;i++){
			ans.insert(i);
		}
	}
	for(set<int>::iterator it = ans.begin();it!=ans.end();it++){
		cout<<(*it)+1<<" ";
	}cout<<endl;
	return 0;
}


#include <bits/stdc++.h>
#define LL long long
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
using namespace std;

typedef pair<int,int> ii;
int n,k,cnt,mx,x,y;
ii a[300100],b[300100];
queue<ii> q;

bool cmp(ii x, ii y){
	return x.sc<y.sc;
}

int main() {
	scanf("%d %d",&n,&k);
	for(int i=0;i<n;i++){
		scanf("%d %d",&a[i].fi,&a[i].sc);
		b[i].fi = a[i].sc;
		b[i].sc = i;
	}
	sort(b,b+n);
	for(int i=0;i<n;i++){
		q.push(mp(b[i].fi,b[i].sc));
	}
	sort(a,a+n);
	set<int> st,ans;
	for(int i=0;i<n;i++){
		while(!q.empty()){
			x = q.front().fi;
			y = q.front().sc;
			if(a[i].fi>x){
				cnt--;
				st.erase(y);
				q.pop();
			}
			else break;
		}
		st.insert(i);
		cnt++;
		int nxt = q.front().fi;
		if(cnt>=k && nxt-a[i].fi+1>mx){
			mx = nxt-a[i].fi+1;
			ans = st;
		}
	}
	while(!q.empty()){
		x = q.front().fi;
		y = q.front().sc;
		set<int>::iterator it = st.end();
		it--;

		cnt--;
		st.erase(y);
		int nxt = q.front().fi;
		if(cnt>=k && nxt-a[(*it)].fi+1>mx){
			mx = nxt-a[(*it)].fi+1;
			ans = st;
		}
		q.pop();

	}
	cout<<mx<<endl;
	if(mx==0){
		for(int i=0;i<k;i++){
			ans.insert(i);
		}
	}
	for(set<int>::iterator it = ans.begin();it!=ans.end();it++){
		cout<<(*it)+1<<" ";
	}cout<<endl;
	return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <map>
#include <set>
#include <iterator>
#include <string>
#include <queue>
#include <cctype>
#include <cassert>
#include <unordered_map>
using namespace std;
#define LL long long
const int Len = 1000000;
const LL l1 = 1LL;
LL n;
LL h1, a1, X1, Y1, h2, a2, X2, Y2;
LL lp1, lp2;
unordered_map<int, int> M;
LL gcd(LL a, LL b)
{
    if (b == 0) return a;
    return gcd(b, a%b);
}
void solve()
{
    M.clear();
    LL cur = h1;
    LL first1 = -1, first2 = -1;
    LL cc = 1;
    lp1 = -1, lp2 = -1;
    while (1) {
        if (M.find(cur) != M.end()) {
            lp1 = cc - M[cur];
            break;
        }
        if (cur == a1 && first1 == -1) {
            first1 = cc;
        }
        M[cur] = cc;
        cur = (X1*cur+Y1)%n;
        ++cc;
    }
    cc = 1;
    cur = h2;
    M.clear();
    while (1) {
        if (M.find(cur) != M.end()) {
            lp2 = cc - M[cur];
            break;
        }
        if (cur == a2 && first2 == -1) {
            first2 = cc;
        }
        M[cur] = cc;
        cur = (X2*cur+Y2)%n;
        ++cc;
    }
    if (first1 == -1 || first2 == -1) {
        puts("-1");
        return;
    }
    assert(first1 > 1 && first2 > 1);
    LL gap = abs(first1-first2);
    LL g = gcd(lp1, lp2);
    if (gap % g) {
        puts("-1");
        return;
    }
    for (int i = 0; i < Len+5; ++i) {
        LL cur = lp1*i + first1 - first2;
        if (cur < 0) continue;
        LL d = cur/lp2;
        if (cur % lp2 == 0 && lp1*i + first1 == lp2*d + first2) {
            cout << lp1*i+first1-1 << endl;
            return;
        }
    }
    puts("-1");
}
int main()
{
    while (cin >> n) {
        cin >> h1 >> a1;
        cin >> X1 >> Y1;
        cin >> h2 >> a2;
        cin >> X2 >> Y2;
        solve();
    }
    return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <map>
#include <set>
#include <iterator>
#include <string>
#include <queue>
#include <cctype>
#include <cassert>
#include <unordered_map>
using namespace std;
#define LL long long
const int Len = 1000000;
const LL l1 = 1LL;
LL n;
LL h1, a1, X1, Y1, h2, a2, X2, Y2;
LL lp1, lp2;
unordered_map<int, int> M;
//map<int, int> M;
LL gcd(LL a, LL b)
{
    if (b == 0) return a;
    return gcd(b, a%b);
}
bool check(LL cur, LL lp, LL x, LL y)
{
    LL tmp = cur;
    for (int i = 0; i < lp; ++i) {
        tmp = (x*tmp+y)%n;
    }
    return tmp == cur;
}
void solve()
{
    M.clear();
    LL cur = h1;
    LL first1 = -1, first2 = -1;
    LL cc = 1;
    lp1 = -1, lp2 = -1;
    while (1) {
        if (M.find(cur) != M.end()) {
            lp1 = cc - M[cur];
            break;
        }
        if (cur == a1 && first1 == -1) {
            first1 = cc;
        }
        M[cur] = cc;
        cur = (X1*cur+Y1)%n;
        ++cc;
    }
    cc = 1;
    cur = h2;
    M.clear();
    while (1) {
        if (M.find(cur) != M.end()) {
            lp2 = cc - M[cur];
            break;
        }
        if (cur == a2 && first2 == -1) {
            first2 = cc;
        }
        M[cur] = cc;
        cur = (X2*cur+Y2)%n;
        ++cc;
    }
    if (first1 == -1 || first2 == -1) {
        puts("-1");
        return;
    }
    if (first1 == first2) {
        cout << first1-1 << endl;
        return;
    }
    if (!check(first1, lp1, X1, Y1) || !check(first2, lp2, X2, Y2)) {
        puts("-1");
        return;
    }
    //cout << "first: " << first1 << " " << first2 << endl;
    //cout << "lp: " << lp1 << " " << lp2 << endl;
    assert(first1 > 1 && first2 > 1);
    LL gap = abs(first1-first2);
    LL g = gcd(lp1, lp2);
    if (gap % g) {
        puts("-1");
        return;
    }
    for (int i = 0; i < Len+5; ++i) {
        LL cur = lp1*i + first1 - first2;
        if (cur < 0) continue;
        LL d = cur/lp2;
        if (cur % lp2 == 0 && lp1*i + first1 == lp2*d + first2) {
            cout << lp1*i+first1-1 << endl;
            return;
        }
    }
    puts("-1");
}
void solve1()
{
    puts("check");
    LL cur1 = h1, cur2 = h2;
    for (int i = 0; i < 10; ++i) {
        cout << "cur: " << cur1 << " " << cur2 << endl;
        cur1 = (X1*cur1+Y1)%n, cur2 = (X2*cur2+Y2)%n;
    }
}
int main()
{
    while (cin >> n) {
        cin >> h1 >> a1;
        cin >> X1 >> Y1;
        cin >> h2 >> a2;
        cin >> X2 >> Y2;
        solve();
        //solve1();
    }
    return 0;
}


#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <iostream>
using namespace std;

const double pi=acos(-1.0);
double eps=0.000001;
__int64 vis1[1000006];
__int64 vis2[1000006];
__int64 when1[1000006];
__int64 when2[1000006];
__int64 gcdc(__int64 a,__int64 b){
    if(b==0)
        return a;
	return gcdc(b,a%b);
}
__int64 t,p,c;
void exgcd(__int64 a,__int64 b,__int64&d,__int64&x,__int64&y)//ax+by=gcd(a,b)
{
    if(!b)
    {
        d=a;
        x=1;
        y=0;
    }
    else
    {
        exgcd(b,a%b,d,y,x);
        y-=x*(a/b);
    }
}

__int64 main()
{
	__int64 h1,h2,x1,x2,y1,y2,a1,a2 ;
	__int64 m;
	cin>>m;
	cin>>h1>>a1;
	cin>>x1>>y1;
	cin>>h2>>a2;
	cin>>x2>>y2;

	__int64 tmp1=h1;
	__int64 tmp2=h2;
	__int64 cun=0;
	while(cun<=2*m)
	{
		cun++;
		tmp1=(tmp1*x1+y1)%m;
		if (tmp1==a1&&vis1[a1]) break;
		vis1[tmp1]=1;
		when1[tmp1]=cun;
	}
	__int64 len1=cun-when1[a1];
	__int64 t1=when1[a1];
	if (t1==0){printf("-1\n");return 0;}
	cun=0;
	while(cun<=2*m)
	{
		cun++;
		tmp2=(tmp2*x2+y2)%m;
		if (tmp2==a2&&vis2[a2]) break;
		vis2[tmp2]=1;
		when2[tmp2]=cun;
	}
	__int64 len2=cun-when2[a2];

	__int64 t2=when2[a2];
	if (t2==0){printf("-1\n");return 0;}

	__int64 every=len1-len2;

	for (__int64 i=1;i<=2*m;i++)
	{

		if (t1==t2) {printf("%d\n",t1);return 0;}
		else
			if (t1>t2)
				t2+=len2;
			else
				t1+=len1;
	}

	return 0;

}


#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <iostream>
using namespace std;

const double pi=acos(-1.0);
double eps=0.000001;
int vis1[1000006];
int vis2[1000006];
int when1[1000006];
int when2[1000006];
  __int64 gcdc(__int64 a,__int64 b){
    if(b==0)
        return a;
        return gcdc(b,a%b);
}
__int64 t,p,c;
void extend_euild(__int64 a, __int64 b)
{
	if (b==0)
	{
		t=1;
		p=0;

	}
	else
	{
		extend_euild(b,a%b);
		__int64 tmp=t;
		t=p;
		p=tmp-a/b*p;
	}
}
int main()
{
int h1,h2,x1,x2,y1,y2,a1,a2 ;
int m;
cin>>m;
cin>>h1>>a1;
cin>>x1>>y1;
cin>>h2>>a2;
cin>>x2>>y2;

int tmp1=h1;
int tmp2=h2;
int cun=0;
while(cun<=2*m)
{
	cun++;
	tmp1=(tmp1*x1+y1)%m;
	if (tmp1==h1) break;
	vis1[tmp1]=1;
	when1[tmp1]=cun;
}
int len1=cun-1;
int t1=when1[a1];
if (t1==0){printf("-1\n");return 0;}
cun=0;
while(cun<=2*m)
{
	cun++;
	tmp2=(tmp2*x2+y2)%m;
	if (tmp2==h2) break;
	vis2[tmp2]=1;
	when2[tmp2]=cun;
}
int len2=cun-1;

int t2=when2[a2];
if (t2==0){printf("-1\n");return 0;}

int every=len1-len2;

if (t1==t2) {printf("%d\n",t1);return 0;}

//dis=t2-t1=dis=a*every+b*m;
//a*x+
	__int64 a=every;
	__int64 b=m;
	__int64 d=t2-t1;
 	__int64 gcd=gcdc(a,b);

	if (d%gcd)
	{
		printf("-1\n");
		return 0;
	}

        extend_euild( a, b );

        t*=  d/gcd ;
        while( t< 0 )
        {
            t+= b;
        }
        printf( "%I64d\n", t%b );

	return 0;

}


#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <iostream>
using namespace std;

const double pi=acos(-1.0);
double eps=0.000001;
__int64 vis1[1000006];
__int64 vis2[1000006];
__int64 when1[1000006];
__int64 when2[1000006];
__int64 gcdc(__int64 a,__int64 b){
    if(b==0)
        return a;
	return gcdc(b,a%b);
}
__int64 t,p,c;
void exgcd(__int64 a,__int64 b,__int64&d,__int64&x,__int64&y)//ax+by=gcd(a,b)
{
    if(!b)
    {
        d=a;
        x=1;
        y=0;
    }
    else
    {
        exgcd(b,a%b,d,y,x);
        y-=x*(a/b);
    }
}

int main()
{
	__int64 h1,h2,x1,x2,y1,y2,a1,a2 ;
	__int64 m;
	scanf("%I64d",&m);
	scanf("%I64d%I64d",&h1,&a1);
	scanf("%I64d%I64d",&x1,&y1);
	scanf("%I64d%I64d",&h2,&a2);
	scanf("%I64d%I64d",&x2,&y2);
	__int64 tmp1=h1;
	__int64 tmp2=h2;
	__int64 cun=0;
	while(cun<=2*m)
	{
		cun++;
		tmp1=(tmp1*x1+y1)%m;
		if (tmp1==a1&&vis1[a1]) break;
		vis1[tmp1]=1;
		when1[tmp1]=cun;
	}
	__int64 len1=cun-when1[a1];
	__int64 t1=when1[a1];
	if (t1==0){printf("-1\n");return 0;}
	cun=0;
	while(cun<=2*m)
	{
		cun++;
		tmp2=(tmp2*x2+y2)%m;
		if (tmp2==a2&&vis2[a2]) break;
		vis2[tmp2]=1;
		when2[tmp2]=cun;
	}
	__int64 len2=cun-when2[a2];

	__int64 t2=when2[a2];
	if (t2==0){printf("-1\n");return 0;}

	for (__int64 i=1;i<=2*m;i++)
	{

		if (t1==t2) {printf("%I64d\n",t1);return 0;}
		else
			if (t1>t2)
				t2+=len2;
			else
				t1+=len1;
	}
	printf("-1\n");

	return 0;

}


#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <iostream>
using namespace std;

const double pi=acos(-1.0);
double eps=0.000001;
__int64 vis1[1000006];
__int64 vis2[1000006];
__int64 when1[1000006];
__int64 when2[1000006];
__int64 gcdc(__int64 a,__int64 b){
    if(b==0)
        return a;
	return gcdc(b,a%b);
}
__int64 t,p,c;
void exgcd(__int64 a,__int64 b,__int64&d,__int64&x,__int64&y)//ax+by=gcd(a,b)
{
    if(!b)
    {
        d=a;
        x=1;
        y=0;
    }
    else
    {
        exgcd(b,a%b,d,y,x);
        y-=x*(a/b);
    }
}

int main()
{
	__int64 h1,h2,x1,x2,y1,y2,a1,a2 ;
	__int64 m;
	scanf("%I64d",&m);
	scanf("%I64d%I64d",&h1,&a1);
	scanf("%I64d%I64d",&x1,&y1);
	scanf("%I64d%I64d",&h2,&a2);
	scanf("%I64d%I64d",&x2,&y2);
	__int64 tmp1=h1;
	__int64 tmp2=h2;
	__int64 cun=0;
	while(cun<=2*m)
	{
		cun++;
		tmp1=(tmp1*x1+y1)%m;
		if (tmp1==a1&&vis1[a1]) break;
		vis1[tmp1]=1;
		when1[tmp1]=cun;
	}
	__int64 len1=cun-when1[a1];
	__int64 t1=when1[a1];
	if (t1==0){printf("-1\n");return 0;}
	cun=0;
	while(cun<=2*m)
	{
		cun++;
		tmp2=(tmp2*x2+y2)%m;
		if (tmp2==a2&&vis2[a2]) break;
		vis2[tmp2]=1;
		when2[tmp2]=cun;
	}
	__int64 len2=cun-when2[a2];

	__int64 t2=when2[a2];
	if (t2==0){printf("-1\n");return 0;}

	__int64 every=len1-len2;

	for (__int64 i=1;i<=2*m;i++)
	{

		if (t1==t2) {printf("%d\n",t1);return 0;}
		else
			if (t1>t2)
				t2+=len2;
			else
				t1+=len1;
	}

	return 0;

}


#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <iostream>
using namespace std;

const double pi=acos(-1.0);
double eps=0.000001;
int vis1[1000006];
int vis2[1000006];
int when1[1000006];
int when2[1000006];
  __int64 gcdc(__int64 a,__int64 b){
    if(b==0)
        return a;
        return gcdc(b,a%b);
}
__int64 t,p,c;
void extend_euild(__int64 a, __int64 b)
{
	if (b==0)
	{
		t=1;
		p=0;

	}
	else
	{
		extend_euild(b,a%b);
		__int64 tmp=t;
		t=p;
		p=tmp-a/b*p;
	}
}
int main()
{
int h1,h2,x1,x2,y1,y2,a1,a2 ;
int m;
cin>>m;
cin>>h1>>a1;
cin>>x1>>y1;
cin>>h2>>a2;
cin>>x2>>y2;

int tmp1=h1;
int tmp2=h2;
int cun=0;
while(cun<=2*m)
{
	cun++;
	tmp1=(tmp1*x1+y1)%m;
	if (tmp1==a1&&vis1[a1]) break;
	 vis1[tmp1]=1;
	when1[tmp1]=cun;
}
int len1=cun-when1[a1];
 int t1=when1[a1];
if (t1==0){printf("-1\n");return 0;}
cun=0;
while(cun<=2*m)
{
	cun++;
	tmp2=(tmp2*x2+y2)%m;
	if (tmp2==a2&&vis2[a2]) break;
	vis2[tmp2]=1;
 	when2[tmp2]=cun;
}
int len2=cun-when2[a2];

int t2=when2[a2];
if (t2==0){printf("-1\n");return 0;}

int every=len1-len2;

if (t1==t2) {printf("%d\n",t1);return 0;}

//dis=t2-t1+(h2-h1)=dis=a*every+b*m;
//a*x+
	__int64 b=len1;
	__int64 a=len2;
	__int64 d=(t2-t1);
 	__int64 gcd=gcdc(a,b);

	if (d%gcd)
	{
		printf("-1\n");
		return 0;
	}

        extend_euild( a, b );
      //  t=p;
        t*=  d/gcd ;
        t%=b;
		if (t<0 ) t-=b;
        printf( "%I64d\n", t*len1+t1 );

	return 0;

}


#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <iostream>
using namespace std;

const double pi=acos(-1.0);
double eps=0.000001;
int vis1[1000006];
int vis2[1000006];
int when1[1000006];
int when2[1000006];
  __int64 gcdc(__int64 a,__int64 b){
    if(b==0)
        return a;
        return gcdc(b,a%b);
}
__int64 t,p,c;
void exgcd(__int64 a,__int64 b,__int64&d,__int64&x,__int64&y)//ax+by=gcd(a,b)
{
    if(!b)
    {
        d=a;
        x=1;
        y=0;
    }
    else
    {
        exgcd(b,a%b,d,y,x);
        y-=x*(a/b);
    }
}

int main()
{
int h1,h2,x1,x2,y1,y2,a1,a2 ;
int m;
cin>>m;
cin>>h1>>a1;
cin>>x1>>y1;
cin>>h2>>a2;
cin>>x2>>y2;

int tmp1=h1;
int tmp2=h2;
int cun=0;
while(cun<=2*m)
{
	cun++;
	tmp1=(tmp1*x1+y1)%m;
	if (tmp1==a1&&vis1[a1]) break;
	 vis1[tmp1]=1;
	when1[tmp1]=cun;
}
int len1=cun-when1[a1];
 int t1=when1[a1];
if (t1==0){printf("-1\n");return 0;}
cun=0;
while(cun<=2*m)
{
	cun++;
	tmp2=(tmp2*x2+y2)%m;
	if (tmp2==a2&&vis2[a2]) break;
	vis2[tmp2]=1;
 	when2[tmp2]=cun;
}
int len2=cun-when2[a2];

int t2=when2[a2];
if (t2==0){printf("-1\n");return 0;}

int every=len1-len2;

if (t1==t2) {printf("%d\n",t1);return 0;}

//dis=t2-t1+(h2-h1)=dis=a*every+b*m;
//a*x+
	__int64 a=len2;
	__int64 b= len1;
	__int64 d=(t1-t2);
	__int64 x,y;
	__int64 gcd;
	exgcd(a,b,gcd,x,y);
	if (d%gcd)
	{
		printf("-1\n");
		return 0;
	}
//	d/=gcd;

//         extend_euild( a, b );

       x*=  d/gcd ;
        x%=b;
		if (x<0 ) x+=b;
        printf( "%I64d\n", x*a+t2 );

	return 0;

}


#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <iostream>
using namespace std;

const double pi=acos(-1.0);
double eps=0.000001;
__int64 vis1[1000006];
__int64 vis2[1000006];
__int64 when1[1000006];
__int64 when2[1000006];
__int64 gcdc(__int64 a,__int64 b){
    if(b==0)
        return a;
	return gcdc(b,a%b);
}
__int64 t,p,c;
void exgcd(__int64 a,__int64 b,__int64&d,__int64&x,__int64&y)//ax+by=gcd(a,b)
{
    if(!b)
    {
        d=a;
        x=1;
        y=0;
    }
    else
    {
        exgcd(b,a%b,d,y,x);
        y-=x*(a/b);
    }
}

__int64 main()
{
	__int64 h1,h2,x1,x2,y1,y2,a1,a2 ;
	__int64 m;
	scanf("%I64d",&m);
	scanf("%I64d%I64d",&h1,&a1);
	scanf("%I64d%I64d",&x1,&y1);
	scanf("%I64d%I64d",&h2,&a2);
	scanf("%I64d%I64d",&x2,&y2);
	__int64 tmp1=h1;
	__int64 tmp2=h2;
	__int64 cun=0;
	while(cun<=2*m)
	{
		cun++;
		tmp1=(tmp1*x1+y1)%m;
		if (tmp1==a1&&vis1[a1]) break;
		vis1[tmp1]=1;
		when1[tmp1]=cun;
	}
	__int64 len1=cun-when1[a1];
	__int64 t1=when1[a1];
	if (t1==0){printf("-1\n");return 0;}
	cun=0;
	while(cun<=2*m)
	{
		cun++;
		tmp2=(tmp2*x2+y2)%m;
		if (tmp2==a2&&vis2[a2]) break;
		vis2[tmp2]=1;
		when2[tmp2]=cun;
	}
	__int64 len2=cun-when2[a2];

	__int64 t2=when2[a2];
	if (t2==0){printf("-1\n");return 0;}

	__int64 every=len1-len2;

	for (__int64 i=1;i<=2*m;i++)
	{

		if (t1==t2) {printf("%d\n",t1);return 0;}
		else
			if (t1>t2)
				t2+=len2;
			else
				t1+=len1;
	}

	return 0;

}


#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <iostream>
using namespace std;

const double pi=acos(-1.0);
double eps=0.000001;
__int64 vis1[1000006];
__int64 vis2[1000006];
__int64 when1[1000006];
__int64 when2[1000006];
__int64 gcdc(__int64 a,__int64 b){
    if(b==0)
        return a;
	return gcdc(b,a%b);
}
__int64 t,p,c;
void exgcd(__int64 a,__int64 b,__int64&d,__int64&x,__int64&y)//ax+by=gcd(a,b)
{
    if(!b)
    {
        d=a;
        x=1;
        y=0;
    }
    else
    {
        exgcd(b,a%b,d,y,x);
        y-=x*(a/b);
    }
}

int main()
{
	__int64 h1,h2,x1,x2,y1,y2,a1,a2 ;
	__int64 m;
	scanf("%I64d",&m);
	scanf("%I64d%I64d",&h1,&a1);
	scanf("%I64d%I64d",&x1,&y1);
	scanf("%I64d%I64d",&h2,&a2);
	scanf("%I64d%I64d",&x2,&y2);
	__int64 tmp1=h1;
	__int64 tmp2=h2;
	__int64 cun=0;
	while(cun<=2*m)
	{
		cun++;
		tmp1=(tmp1*x1+y1)%m;
		if (tmp1==a1&&vis1[a1]) break;
		vis1[tmp1]=1;
		when1[tmp1]=cun;
	}
	__int64 len1=cun-when1[a1];
	__int64 t1=when1[a1];
	if (t1==0){printf("-1\n");return 0;}
	cun=0;
	while(cun<=2*m)
	{
		cun++;
		tmp2=(tmp2*x2+y2)%m;
		if (tmp2==a2&&vis2[a2]) break;
		vis2[tmp2]=1;
		when2[tmp2]=cun;
	}
	__int64 len2=cun-when2[a2];

	__int64 t2=when2[a2];
	if (t2==0){printf("-1\n");return 0;}

	__int64 every=len1-len2;

	for (__int64 i=1;i<=2*m;i++)
	{

		if (t1==t2) {printf("%d\n",t1);return 0;}
		else
			if (t1>t2)
				t2+=len2;
			else
				t1+=len1;
	}
	printf("-1\n");

	return 0;

}