#include <bits/stdc++.h>
using namespace std;
int n, m;
bool c[1508][1508];
int sx, sy;
pair<int, int> v[1508][1508];
const int dx[5] = {1, -1, 0, 0};
const int dy[5] = {0, 0, 1, -1};
int ttt = 0;
void dfs1(int x, int y) {
  v[(x % n + n) % n][(y % m + m) % m] = make_pair(x, y);
  ttt++;
  if (ttt > n * m + 1) {
    cout << "No" << endl;
    exit(0);
  }
  for (int i = 0; i < 4; i++) {
    int xx = x + dx[i];
    int yy = y + dy[i];
    int d = (xx % n + n) % n;
    int e = (yy % m + m) % m;
    if (v[d][e] != make_pair(0, 0) && v[d][e] != make_pair(xx, yy) &&
        c[d][e] != 1) {
      cout << "Yes" << endl;
      exit(0);
    }
    if (v[d][e] != make_pair(xx, yy) && c[d][e] != 1) {
      dfs1(xx, yy);
    }
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      char ch;
      cin >> ch;
      if (ch == 'S') {
        sx = i;
        sy = j;
        c[i][j] = 0;
      } else if (ch == '#') {
        c[i][j] = 1;
      } else if (ch == '.') {
        c[i][j] = 0;
      }
    }
  }
  dfs1(sx, sy);
  cout << "No" << endl;
  return 0;
}
