#include <bits/stdc++.h>
using namespace std;
int n, m;
string G[1508];
pair<int, int> visited[1502][1502];
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, -1, 1};
int abss(int a, int mm) { return (a % mm + mm) % mm; }
string bfs(int x, int y) {
  memset(visited, -1, sizeof visited);
  queue<pair<int, int> > Q;
  Q.push(pair<int, int>(x, y));
  visited[x][y] = pair<int, int>(x, y);
  while (!Q.empty()) {
    pair<int, int> top = Q.front();
    Q.pop();
    for (int i = 0; i < 4; i++) {
      int X = top.first + dx[i], Y = top.second + dy[i];
      x = abss(X, n), y = abss(Y, m);
      if (G[x][y] == '#') continue;
      if (visited[x][y] == pair<int, int>(-1, -1)) {
        visited[x][y] = pair<int, int>(X, Y);
        Q.push(pair<int, int>(X, Y));
      } else if (visited[x][y] == pair<int, int>(X, Y))
        continue;
      else {
        return "Yes";
      }
    }
  }
  return "No";
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> G[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (G[i][j] == 'S') cout << bfs(i, j) << endl;
    }
  }
  return 0;
}
