#include <bits/stdc++.h>
using namespace std;
const long long N = 1505;
char en = '\n';
long long inf = 1e16;
long long mod = 1e9 + 7;
long long power(long long x, long long n, long long mod) {
  long long res = 1;
  x %= mod;
  while (n) {
    if (n & 1) res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}
char arr[N][N];
unordered_map<long long, long long> visited;
long long dir[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
long long n, m;
long long factor;
bool valid(long long r, long long c) {
  return !visited.count(r * factor + c) &&
         arr[(r % n + n) % n][(c % m + m) % m] != '#';
}
bool visited2[N][N];
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  factor = 1e6;
  for (long long i = 0; i < n; i++) {
    string s;
    cin >> s;
    for (long long j = 0; j < m; j++) {
      arr[i][j] = s[j];
    }
  }
  long long ri, cj;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      if (arr[i][j] == 'S') {
        ri = i;
        cj = j;
      }
    }
  }
  queue<pair<long long, long long>> que;
  que.push({ri, cj});
  memset(visited2, false, sizeof(visited2));
  visited[ri * factor + cj];
  visited2[(ri % n + n) % n][(cj % m + m) % m] = true;
  while (!que.empty()) {
    pair<long long, long long> curr = que.front();
    que.pop();
    ri = curr.first, cj = curr.second;
    for (long long k = 0; k < 4; k++) {
      long long ni = ri + dir[k][0], nj = cj + dir[k][1];
      if (valid(ni, nj)) {
        if (visited2[(ni % n + n) % n][(nj % m + m) % m]) {
          cout << "Yes" << en;
          return 0;
        }
        visited2[(ni % n + n) % n][(nj % m + m) % m] = true;
        visited[ni * factor + nj];
        que.push({ni, nj});
      }
    }
  }
  cout << "No" << en;
  return 0;
}
