#include <bits/stdc++.h>
using namespace std;
char buf[2000];
int dx[4] = {0, 0, -1, 1};
int dy[4] = {-1, 1, 0, 0};
int n, m;
pair<int, int> tbl1[1 << 23];
pair<int, int> tbl2[1 << 23];
const int Prime1 = 262139, Prime2 = 40999999;
const pair<int, int> ZERO = make_pair(0, 0);
bool ex(int x, int y) {
  int t1 = x * Prime1 + y * Prime2;
  t1 = abs(t1);
  t1 %= ((1 << 23));
  while (tbl1[t1] != ZERO && tbl1[t1] != make_pair(x, y))
    t1 = (t1 + 1) % (1 << 23);
  if (tbl1[t1] == make_pair(x, y)) return false;
  tbl1[t1] = make_pair(x, y);
  return true;
}
int main() {
  cin >> n >> m;
  vector<string> a;
  for (int i = (0); i < (n); ++i) {
    string s;
    scanf("%s", buf);
    s = buf;
    a.push_back(s);
  }
  pair<int, int> start;
  for (int i = (0); i < (n); ++i) {
    for (int j = (0); j < (m); ++j)
      if (a[i][j] == 'S') start = make_pair(i, j);
  }
  queue<pair<int, int> > q;
  q.push(start);
  ex(start.first, start.second);
  int k = 0;
  while (!q.empty()) {
    if (k > n * m) {
      cout << "Yes\n";
      return 0;
    }
    pair<int, int> v = q.front();
    q.pop();
    for (int i = (0); i < (4); ++i) {
      int x = v.first + dx[i];
      int y = v.second + dy[i];
      int _x = (x % n + n) % n;
      int _y = (y % m + m) % m;
      if (a[_x][_y] != '#' && ex(x, y)) {
        k++;
        q.push(make_pair(x, y));
      }
    }
  }
  cout << "No\n";
  return 0;
}
