#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
double fixAngle(double A) { return A > 1 ? 1 : (A < -1 ? -1 : A); }
double dcmp(double a, double b) {
  return fabs(a - b) < 1e-6 ? 0 : a > b ? 1 : -1;
}
const int MAX = (int)1e3 + 5;
int n, m;
vector<string> grid;
pair<int, int> visited[1500 + 5][1500 + 5];
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
bool bfs(int xx, int yy) {
  visited[xx][yy] = {xx, yy};
  queue<pair<long long, long long> > q;
  q.push({xx, yy});
  while (!q.empty()) {
    auto t = q.front();
    q.pop();
    for (long long i = 0; i < 4; i++) {
      int x = t.first + dx[i];
      int y = t.second + dy[i];
      if (grid[((x % n) + n) % n][((y % m) + m) % m] == '#') continue;
      if (visited[((x % n) + n) % n][((y % m) + m) % m] == make_pair(x, y))
        continue;
      else {
        if (visited[((x % n) + n) % n][((y % m) + m) % m] !=
            make_pair(-1, -1)) {
          return true;
        }
        visited[((x % n) + n) % n][((y % m) + m) % m] = make_pair(x, y);
        q.push({x, y});
      }
    }
  }
  return false;
}
int main() {
  for (long long i = 0; i < 1500 + 5; i++)
    for (long long j = 0; j < 1500 + 5; j++) visited[i][j] = {-1, -1};
  cin >> n >> m;
  int x;
  int y;
  for (long long i = 0; i < n; i++) {
    string s;
    cin >> s;
    for (long long j = 0; j < m; j++) {
      if (s[j] == 'S') {
        x = i;
        y = j;
        s[j] = '.';
      }
    }
    grid.push_back(s);
  }
  if (bfs(x, y)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
