#include <bits/stdc++.h>
using namespace std;
const int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0};
char arr[1505][1505];
pair<int, int> visited[1505][1505];
int n, m;
bool flag = 0;
void dfs(int sx, int sy) {
  int a = sx % n, b = sy % m;
  if (visited[a][b] == make_pair(sx, sy) || arr[a][b] == '#' || flag) return;
  if (visited[a][b] != make_pair(0, 0)) {
    flag = 1;
    return;
  }
  visited[a][b] = make_pair(sx, sy);
  for (int i = 0; i < 4; ++i) dfs(sx + dx[i], sy + dy[i]);
  return;
}
int main() {
  int sx, sy;
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    string str;
    cin >> str;
    for (int j = 0; j < m; ++j) {
      arr[i][j] = str[j];
      if (arr[i][j] == 'S') arr[i][j] = '.', sx = i, sy = j;
    }
  }
  dfs(sx + n * m, sy + n * m);
  if (flag)
    cout << "Yes";
  else
    cout << "No";
}
