#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int,int>;
int main()
{
    int h, w;
    cin >> h >> w;

    vector<char> bbb(w);


    rep(i, w){
        cin >> bbb[i];
    }

    int ans  = 0;

   for(int i = 0;i < h; i++){
        vector<char> ccc(w);
           rep(k, w){;
               cin >> ccc[k];
           }
        

       for(int j = 0; j < w - 1; j++){

           if(bbb[j] != bbb[j + 1] && ccc[j] == ccc[j + 1]){
               ans++;              
           }
          
          if(bbb[j] == bbb[j + 1] && ccc[j] != ccc[j + 1]){
              ans++;
          }
          int a;
          a = ccc[j];

          bbb[j] = a;
       }
    
}

    cout << ans << endl;


return 0;
}
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll x,sum,maxn=-0x3f3f3f3f3f3f3f3f,minn=0x3f3f3f3f3f3f3f3f,n,a,t,q;
int main()
{
    cin>>n;
    while(n--)
    {
        cin>>a>>t;
        if(t==1)
        {
            sum+=a;
            maxn+=a;
            minn+=a;
        }
        if(t==2)
        {
            maxn=max(a,maxn);
            minn=max(minn,a);
        }
        if(t==3)
        {
            minn=min(a,minn);
            maxn=min(a,maxn);
        }
    }
    cin>>q;
    while(q--)
    {
        cin>>x;
        cout<<min(max(x+sum,maxn),minn)<<endl;

    }



    return 0;
}
