#include <bits/stdc++.h>
using namespace std;
template <class t>
t mag(t a) {
  return a > 0 ? a : -a;
}
template <class T>
T cdiv(T num, T den) {
  return (num / den) + (num % den > 0);
}
std::ifstream term("/dev/tty");
std::string tempstring;
using ll = int_fast64_t;
using ii = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<ii>;
int tc = 1;
const ll sij = 40001000;
const ll mod = 1000000007ll;
ll n, m;
bool vis[1510][1510];
string vec[1510];
int mx[] = {0, 0, -1, 1}, my[] = {-1, 1, 0, 0};
ii st;
ll msk[1510][1510], msy[1510][1510];
int esc(int tcase) {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> vec[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (vec[i][j] == 'S') {
        st = {i, j};
      }
    }
  }
  st.first = st.first + n * mod;
  st.second = st.second + m * mod;
  msk[st.first % n][st.second % m] = st.first;
  msy[st.first % n][st.second % m] = st.second;
  queue<ii> q;
  q.push(st);
  while (!q.empty()) {
    ii cr = q.front();
    q.pop();
    for (int i = 0; i < 4; i++) {
      ll gx = cr.first + mx[i], gy = cr.second + my[i];
      if (vec[gx % n][gy % m] == '#') continue;
      if (msk[gx % n][gy % m] == 0) {
        q.push({gx, gy});
        msk[gx % n][gy % m] = gx;
        msy[gx % n][gy % m] = gy;
        continue;
      }
      if (msk[gx % n][gy % m] != gx or msy[gx % n][gy % m] != gy) {
        cout << "Yes";
        return 0;
      }
    }
  }
  cout << "No";
  return 0;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  for (int i = 1; i <= tc; i++) esc(i);
}
