#include <bits/stdc++.h>
long long fpow(long long x, long long y, long long p = 1000000007) {
  x = x % p;
  long long sum = 1;
  while (y) {
    if (y & 1) sum = sum * x;
    sum %= p;
    y = y >> 1;
    x = x * x;
    x %= p;
  }
  return sum;
}
long long fact[1000007] = {0};
void facto() {
  fact[0] = 1;
  fact[1] = 1;
  for (long long i = 2; i < 100007; i++)
    fact[i] = (fact[i - 1] * i) % 1000000007;
}
long long ncr(long long n, long long r) {
  long long res = 1;
  res = fact[n];
  res = (res * (fpow(fact[r], 1000000007 - 2))) % 1000000007;
  res = (res * (fpow(fact[n - r], 1000000007 - 2))) % 1000000007;
  return res;
}
long long npr(long long n, long long r) {
  long long res = 1;
  res = fact[n];
  res = (res * (fpow(fact[n - r], 1000000007 - 2))) % 1000000007;
  return res;
}
long long modmul(long long x, long long y) { return (x * y) % 1000000007; }
long long modadd(long long x, long long y) { return (x + y) % 1000000007; }
long long modsub(long long x, long long y) {
  return (x - y + 1000000007) % 1000000007;
}
long long xx[4] = {1, 0, -1, 0};
long long yy[4] = {0, 1, 0, -1};
using namespace std;
long long n, m;
char a[1501][1501];
pair<long long, long long> val[1501][1501];
long long vis[1501][1501];
long long dfs(long long x, long long y) {
  long long ox, oy;
  ox = (x % n + n) % n;
  oy = (y % m + m) % m;
  if (vis[ox][oy]) {
    if (val[ox][oy] != make_pair(x, y))
      return 1;
    else {
      return 0;
    }
  }
  if (a[ox][oy] == '#') return 0;
  val[ox][oy] = {x, y};
  vis[ox][oy] = 1;
  for (long long i = 0; i < 4; i++) {
    if (dfs(x + xx[i], y + yy[i])) return 1;
  }
  return 0;
}
signed main() {
  cin >> n >> m;
  long long xx, yy;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      cin >> a[i][j];
      if (a[i][j] == 'S') {
        xx = i;
        yy = j;
      }
    }
  }
  if (dfs(xx, yy)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
