#include <iostream>
#include <vector>
using namespace std;
void solve(){
int n,m;
cin >> n >> m;
vector<vector<char>> a(n, vector<char>(m));
for(int i = 0; i < n; i++)
for(int j = 0; j < m; j++)
cin >> a[i][j];
int i = 0,ans = -1;
while(i < n){
int cnt = 1,j = 1;
while(a[i][j] == a[i][j-1] && j < m){
cnt++;
j++;
}
if(cnt == m)
ans = i;
i++;
if(ans == -1)
cout << "No solution";
else
cout << ans + 1;
signed main(){
solve();
#include <iostream>
#include <vector>
using namespace std;
void solve(){
int n,m;
cin >> n >> m;
vector<vector<char>> a(n, vector<char>(m));
for(int i = 0; i < n; i++)
for(int j = 0; j < m; j++)
cin >> a[i][j];
int i = 0,ans = -1;
while(i < n){
int cnt = 1,j = 1;
while(a[i][j] == a[i][j-1] && j < m){
cnt++;
j++;
}
if(cnt == m)
ans = i;
i++;
}
if(ans == -1)
cout << "No solution";
else
cout << ans + 1;
}
signed main(){
solve();
}