#include using namespace std; #include using namespace atcoder; using mint = atcoder::static_modint<998244353>; // // using mint = atcoder::static_modint<1000000007>; using ld = long double; using ll = long long; #define mp(a,b) make_pair(a,b) #define rep(i,s,n) for(int i=s; i<(int)n; i++) const vector dx{1,0,-1,0},dy{0,1,0,-1}; int n,m; bool solve(){ string s;cin >> s; ll x=0,y=0; //通過位置と通過方向のペア vector> A; vector> B; for(char c:s){ ll u=x,v=y; if(c=='U')v++; if(c=='D')v--; if(c=='R')u++; if(c=='L')u--; // cout << u << " " << v << "\n"; if((2*y-1)*(2*v-1)<0){ //y=0.5を縦断 pair p; if(x<0)p.first=-1; else if(x==0)p.first=0; else p.first=1; if(y==0){ //下から上に通過 p.second=1; } else{ //上から下 p.second=-1; } if(A.size()>0 && A.back().first==p.first && A.back().second==-p.second)A.pop_back(); else A.push_back(p); B.push_back(p); } x=u,y=v; } // for(auto [x,y]:B)cout << x << " " << y << "\n"; // cout << "\n"; return A.size()==0; } int main(){ cin >> n >> m; int ans=0; rep(i,0,n)ans+=solve(); cout << ans; }