#include <bits/stdc++.h>
using namespace std;
const double PI = 2.0 * acos(0.0);
const double EPS = 1e-6;
char mapp[1505][1505];
pair<int, int> record[1505][1505];
int n, m;
const int OFF_X[4] = {0, 0, 1, -1};
const int OFF_Y[4] = {1, -1, 0, 0};
bool DFS(int x, int y, int dx, int dy) {
  if (mapp[x][y] == 'S') return record[x][y] != make_pair(dx, dy);
  mapp[x][y] = 'S';
  record[x][y] = make_pair(dx, dy);
  for (int k = 0; k < 4; k++) {
    int xx = (x + OFF_X[k] + n) % n;
    int yy = (y + OFF_Y[k] + m) % m;
    if (mapp[xx][yy] != '#' && DFS(xx, yy, dx + OFF_X[k], dy + OFF_Y[k]))
      return true;
  }
  return false;
}
int main() {
  scanf("%d %d", &n, &m);
  pair<int, int> s;
  for (int r = 0; r < n; r++) {
    scanf("%s", mapp[r]);
    for (int c = 0; c < m; c++)
      if (mapp[r][c] == 'S') {
        s = make_pair(r, c);
        mapp[r][c] = '.';
      }
  }
  puts(DFS(s.first, s.second, 0, 0) ? "Yes" : "No");
  return 0;
}
