#include <bits/stdc++.h>
using namespace std;
pair<int, int> M[1555][1555];
int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, -1, 1};
int vis[1555][1555];
char mp[1555][1555];
int n, m;
int flag;
pair<int, int> getXY(int x, int y) {
  int xx = (x % n + n) % n;
  int yy = (y % m + m) % m;
  return make_pair(xx, yy);
}
void dfs(int x, int y) {
  if (flag == 1) return;
  pair<int, int> tn = getXY(x, y);
  int nx = tn.first;
  int ny = tn.second;
  if (vis[nx][ny] && (M[nx][ny].first != x || M[nx][ny].second != y)) {
    flag = 1;
    return;
  }
  if (vis[nx][ny]) return;
  M[nx][ny] = make_pair(x, y);
  vis[nx][ny]++;
  for (int i = 0; i < 4; i++) {
    int xx = x + dx[i];
    int yy = y + dy[i];
    pair<int, int> tw = getXY(xx, yy);
    if (vis[tw.first][tw.second] > 1 || mp[tw.first][tw.second] == '#')
      continue;
    dfs(xx, yy);
  }
}
int main() {
  scanf("%d%d", &n, &m);
  int ret;
  int x, y;
  for (int i = 0; i < n; i++) scanf("%s", mp[i]);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (mp[i][j] == 'S') x = i, y = j;
    }
  }
  dfs(x, y);
  if (flag == 1)
    printf("Yes\n");
  else
    printf("No\n");
}
