#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<long long> Vll;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793
 


int main(){
    int h,w;
    cin >> h >> w;
    vector<vector<char>> s(h,vector<char>(w));
    vector<vector<int>> ss(h+1,vector<int>(w+1));
    rep(i,h){
        rep(j,w){
            cin >> s[i][j];
            if(s[i][j]=='#'){
                ss[i][j]++;
                ss[i+1][j]++;
                ss[i][j+1]++;
                ss[i+1][j+1]++;
            }
        }
    }
    ll ans=0;
    rep(i,h+1){
        rep(j,w+1){
            if(ss[i][j]%2==1)ans++;
        }
    }
    cout << ans << endl;
}


#include<bits/stdc++.h>
#define lli long long
#define lld double
#define test int t;cin>>t;while(t--)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
#define  mod 1000000007
#define ff first
#define ss second
#define ppl pair<lli , lli>
#define ppi pair<int , int>
#define large 1000000000000000000
using namespace std;
bool comp(const ppl &a,const ppl &b)
{
    return (a.ss < b.ss);
}
void solve()
{
    lli n , money , pre = 0;
    cin >> n >> money;
    vector<ppl>v(n);
    for(int i = 0 ; i < n ; i++)
    {
        cin >> v[i].ff >> v[i].ss;
    }
    sort(v.begin() , v.end());
    for(int i = 0 ; i < n ; i++)
    {
        if(money < (v[i].ff - pre))
        {
            break;
        }
        money -= (v[i].ff - pre);
        pre = v[i].ff;
        money += v[i].ss;
    }
    pre += money;
    cout << pre;
}
int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w" , stdout);
#endif  
    fast_io;
    //test
    {
        solve();
    }
    return 0;
}