/*#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
#include<bits/stdc++.h>
#define ll long long
#define inf 1000000005
#define put putchar('\n')
#define F(i,a,b) for (int i=(a);i<=(b);i++)
#define D(i,a,b) for (int i=(a);i>=(b);i--)
#define go(i,t) for (int i=head[t];i;i=Next[i])
#define sqr(x) ((x)*(x))
#define re register
#define mp make_pair
#define fi first
#define se second
#define pa pair<int,int>
#define pb push_back
#define be begin()
#define en end()
#define ret return puts("-1"),0;
#define mod 1000000007
#define N 500055
#define int ll
using namespace std;
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline int read(){char c=getchar();int tot=1;while ((c<'0'|| c>'9')&&c!='-') c=getchar();if (c=='-'){tot=-1;c=getchar();}
int sum=0;while (c>='0'&&c<='9'){sum=sum*10+c-'0';c=getchar();}return sum*tot;}
inline void wr(int x){if (x<0) {putchar('-');wr(-x);return;}if(x>=10)wr(x/10);putchar(x%10+'0');}
inline void wrn(int x){wr(x);put;}inline void wri(int x){wr(x);putchar(' ');}
inline void wrn(int x,int y){wri(x);wrn(y);}inline void wrn(int a,int b,int c){wri(a);wrn(b,c);}
int n,m,vis[N],co[N],I,P,Q;
int nedge,Next[N*2],head[N],to[N*2];
#define V to[i]
void add(int a,int b){
	Next[++nedge]=head[a];head[a]=nedge;to[nedge]=b;
}
void add_ne(int a,int b){add(a,b);add(b,a);}
bool dfs(int x){
	vis[x]=1;
	bool num=1;
	go(i,x){
		if (vis[V]) num&=(co[x]!=co[V]);
		else co[V]=co[x]^1,num&=dfs(V);
	}
	return num;
}
signed main(){
	n=read();m=read();
	F(i,1,m){
		add_ne(read(),read());
	}
	F(i,1,n){
		if (!vis[i]){
			if (head[i]==0) I++;
			else if (dfs(i)) Q++;
			else P++;
		}
	}
	wrn(I*I+I*(n-I)*2+P*Q*2+P*P+Q*Q*2);
	return 0;
}
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
ll N, S, X[100500], P[100500];

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> S;
    for(int i = 1; i <= N; i++) cin >> X[i] >> P[i];
    vector<l_l> before;
    vector<l_l> after;
    for(int i = 1; i <= N; i++) {
        if(X[i] >= S) break;
        before.push_back({X[i], P[i]});
    }
    for(int i = N; i >= 1; i--) {
        if(X[i] <= S) break;
        after.push_back({X[i], P[i]});
    }
    ll sum = 0;
    int cheer = 1;
    vector<l_l> que;
    int after_index = 0;
    int before_index = 0;
    for(int time = 1; time <= N; time++) {
        if(after_index >= after.size()) {
            que.push_back(before[before_index]);
            before_index++;
            continue;
        }
        if(before_index >= before.size()) {
            que.push_back(after[after_index]);
            after_index++;
            continue;
        }
        ll left = before[before_index].second;
        ll right = after[after_index].second;
        if(cheer == 1) {
            left += sum;
        } else {
            right += sum;
        }
        if(right > left) {
            que.push_back(before[before_index]);
            sum += before[before_index].second;
            before_index++;
            cheer = 0;
        } else {
            que.push_back(after[after_index]);
            sum += after[after_index].second;
            after_index++;
            cheer = 1;
        }
    }
    ll ans = 0;
    ll now = S;
    for(int i = que.size() - 1; i >= 0; i--) {
        ans += abs(que[i].first - now);
        now = que[i].first;
    }
    cout << ans << endl;
    return 0;
}
