#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<pair<int, int> > > visited(
      n, vector<pair<int, int> >(m, make_pair(3000, 3000)));
  pair<int, int> start_pos;
  for (int i = 0; i < n; i++) {
    string row;
    cin >> row;
    for (int j = 0; j < m; j++) {
      if (row[j] == '#') {
        visited[i][j] = make_pair(-3000, -3000);
      } else if (row[j] == 'S') {
        start_pos.first = i;
        start_pos.second = j;
      }
    }
  }
  stack<pair<int, int> > stk;
  stk.push(start_pos);
  pair<int, int> curr_pos;
  while (!stk.empty()) {
    curr_pos = stk.top();
    stk.pop();
    int x = curr_pos.first;
    int y = curr_pos.second;
    int x_tmp = x;
    int y_tmp = y;
    while (x_tmp < 0) {
      x_tmp += n;
    }
    while (y_tmp < 0) {
      y_tmp += m;
    }
    visited[x_tmp % n][y_tmp % m] = make_pair(x, y);
    x = curr_pos.first;
    y = curr_pos.second;
    for (int x_diff = -1; x_diff <= 1; x_diff++) {
      for (int y_diff = -1; y_diff <= 1; y_diff++) {
        if (abs(x_diff) == abs(y_diff)) {
          continue;
        }
        int i = x + x_diff;
        int j = y + y_diff;
        int i_tmp = i;
        int j_tmp = j;
        while (i_tmp < 0) {
          i_tmp += n;
        }
        while (j_tmp < 0) {
          j_tmp += m;
        }
        if (visited[i_tmp % n][j_tmp % m] == make_pair(3000, 3000)) {
          stk.push(make_pair(i, j));
        } else if (visited[i_tmp % n][j_tmp % m] != make_pair(-3000, -3000) &&
                   visited[i_tmp % n][j_tmp % m] != make_pair(i, j)) {
          cout << "Yes\n";
          return 0;
        }
      }
    }
  }
  cout << "No\n";
  return 0;
}
