#include <iostream>
#include <map>
#define int long long
using namespace std;
map<int,int>mp;
int n,k,x = 1e9,y,oq,d,ans;
char c;
signed main()
{
cin >> n >> k;
for(int i = 1;i <= n;i ++)
{
cin >> x >> c;
if(c == 'L'){mp[y] --;y -= x;mp[y] ++;}
else {mp[y + 1] ++;y += x;mp[y + 1] --;}
}
map<int,int>::iterator kk,kk2;
for(kk = mp.begin();kk != mp.end();kk ++)
{
oq += (kk -> second);
kk2 = kk;kk2 ++;
if(oq >= k && kk2 != mp.end())ans += (kk2 -> first) - (kk -> first);
d = (kk -> first);
}
cout << ans << endl;
}