#include <bits/stdc++.h>
using namespace std;
bool vis[2018][2018];
char ch[2018][2018];
pair<int, int> ma[2018][2018];
int dx[4] = {0, 0, -1, 1};
int dy[4] = {1, -1, 0, 0};
int n, m;
void dfs(int xn, int yn) {
  int x = xn, y = yn;
  while (x < 0) x += n;
  while (y < 0) y += m;
  x %= n;
  y %= m;
  if (vis[x][y] && (ma[x][y].first != xn || ma[x][y].second != yn)) {
    cout << "Yes" << endl;
    exit(0);
  }
  if (vis[x][y] || ch[x][y] == '#') return;
  ma[x][y] = make_pair(xn, yn);
  vis[x][y] = 1;
  for (int i = 0; i < 4; i++) dfs(xn + dx[i], yn + dy[i]);
}
int main() {
  scanf("%d%d", &n, &m);
  {
    memset(vis, 0, sizeof vis);
    int sx, sy;
    for (int i = 0; i < n; i++) scanf("%s", ch[i]);
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++) {
        if (ch[i][j] == 'S') sx = i, sy = j;
      }
    dfs(sx, sy);
    cout << "No" << endl;
  }
  return 0;
}
