numbers = list(map( int , input().split()))
columns = numbers[0]
rows = numbers[1]
counter = -1
data = {}
stop = 0
for i in range(0 , columns) :
x = input()
g = "not"
s = 'not'
count = 0
for j in range (0 , rows) :
if x[j] == "S" :
if g == "found" :
counter = count + 1 ;
if not f"{counter}" in data :
data[f"{counter}"] = 1
else :
stop = 1
break
elif x[j] == 'G' :
g = 'found'
count = 0
else :
count += 1
print(-1 if len(data) == 0 or stop == 1 else len(data))
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,m,c,d;
char a[1001][1001];
cin>>n>>m;
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
cin>>a[i][j];
for(int i=0;i<n;i++)
{
bool G=0;
for(int j=0;j<m;j++)
{
if(a[i][j]=='S'&&G==0)
{
cout<<-1<<endl;
return 0;
}
else if(a[i][j]=='G')
G=1;
}
}
set<int>s;
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
if(a[i][j]=='S')
c=j;
else if(a[i][j]=='G')
d=j;
}
s.insert(c-d);
}
cout<<s.size()<<endl;
return 0;
}
/**
*/
1641A - Great Sequence | 1537A - Arithmetic Array |
1370A - Maximum GCD | 149A - Business trip |
34A - Reconnaissance 2 | 59A - Word |
462B - Appleman and Card Game | 1560C - Infinity Table |
1605C - Dominant Character | 1399A - Remove Smallest |
208A - Dubstep | 1581A - CQXYM Count Permutations |
337A - Puzzles | 495A - Digital Counter |
796A - Buying A House | 67A - Partial Teacher |
116A - Tram | 1472B - Fair Division |
1281C - Cut and Paste | 141A - Amusing Joke |
112A - Petya and Strings | 677A - Vanya and Fence |
1621A - Stable Arrangement of Rooks | 472A - Design Tutorial Learn from Math |
1368A - C+= | 450A - Jzzhu and Children |
546A - Soldier and Bananas | 32B - Borze |
1651B - Prove Him Wrong | 381A - Sereja and Dima |