#include <bits/stdc++.h>
using namespace std;
mt19937 myrand(chrono::steady_clock::now().time_since_epoch().count());
#pragma comment(linker, "/STACK:336777216")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
template <class L, class R>
ostream& operator<<(ostream& os, pair<L, R> P) {
  return os << "(" << P.first << "," << P.second << ")";
}
template <class L, class R, class M>
ostream& operator<<(ostream& os, tuple<L, R, M> P) {
  return os << "(" << get<0>(P) << "," << get<1>(P) << "," << get<2>(P) << ")";
}
template <class T>
ostream& operator<<(ostream& os, vector<T> V) {
  os << "{ ";
  for (auto v : V) os << v << " ";
  return os << "}";
}
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
const int maxn = (int)1e5 + 5;
const long double EPS = 1e-9;
const int INF = (int)1e18 + 9;
const int mod = (int)1e9 + 7;
int N, M, X = -1, Y = -1;
char a[2000][2000];
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
set<pair<int, int>> se;
int get(int x, int MOD) {
  x %= MOD;
  if (x < 0) {
    x += MOD;
  }
  return x;
}
void dfs(int x, int y, int parentX, int parentY) {
  if ((int)se.size() > N * M) {
    cout << "Yes" << '\n';
    exit(0);
  }
  for (int i = 0; i < 4; i++) {
    int _x = x + dx[i], _y = y + dy[i];
    if (_x == parentX && _y == parentY) {
      continue;
    }
    if (a[get(_x, N)][get(_y, M)] == '#') {
      continue;
    }
    if (se.insert({_x, _y}).second) {
      dfs(x + dx[i], y + dy[i], x, y);
    }
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    string s;
    cin >> s;
    for (int j = 0; j < M; j++) {
      a[i][j] = s[j];
      if (a[i][j] == 'S') X = i, Y = j;
    }
  }
  assert(X != -1 && Y != -1);
  dfs(X, Y, -1, -1);
  cout << ((int)se.size() > N * M ? "Yes" : "No") << '\n';
  return 0;
}
