#include <bits/stdc++.h>
using namespace std;
int n, m;
char g[1510][1510];
pair<int, int> who[1510][1510];
int dir1[4] = {-1, 0, 1, 0};
int dir2[4] = {0, -1, 0, 1};
bool check(int i, int j) { return g[i][j] != '#'; }
void dfs(int i, int j) {
  int A = (i % n + n) % n;
  int B = (j % m + m) % m;
  if (g[A][B] == 1) {
    if (who[A][B].first != i || who[A][B].second != j) {
      cout << "Yes";
      exit(0);
    } else {
      return;
    }
  }
  g[A][B] = 1;
  who[A][B].first = i;
  who[A][B].second = j;
  for (int k = 0; k < 4; k++) {
    int x = i + dir1[k];
    int y = j + dir2[k];
    if (check((x % n + n) % n, (y % m + m) % m)) {
      dfs(x, y);
    }
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%s", g[i]);
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (g[i][j] == 'S') {
        dfs(i, j);
        cout << "No";
        return 0;
      }
    }
  }
  return 0;
}
