#include using namespace std; #define rep(i,a,b) for(int i=(a);i<(b);i++) #define all(a) begin(a),end(a) #define sz(a) (int)(a).size() typedef long long ll; typedef vector vi; typedef pair pii; const ll mod=998244353; int main(){ cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit); int N,M;cin>>N>>M; int ans=0; while(N--){ string S;cin>>S; ll a1=0,a2=0,x=0,y=0; rep(i,0,sz(S)){ ll _x=x,_y=y; if(S[i]=='L')x--; else if(S[i]=='R')x++; else if(S[i]=='U')y++; else y--; a1+=(2*_x-1)*(2*y-1)-(2*x-1)*(2*_y-1); a2+=(2*_x+1)*(2*y-1)-(2*x+1)*(2*_y-1); } if(a1==0&&a2==0)ans++; } cout<