#include <bits/stdc++.h>
using namespace std;
pair<int, int> st[1509][1509];
char s[1509][1509];
int n, m;
int sa = 24000000;
bool mo(pair<int, int> t, int p, int pp) {
  if (t.first == p && t.second == pp) {
    return 1;
  }
  return 0;
}
int baghi(int a, int b) {
  if (a < 0) {
    return b - ((-a) % b);
  }
  return a % b;
}
bool dfs(int x, int y) {
  int xx = baghi(x, n);
  int yy = baghi(y, m);
  int gy, gx;
  if (s[baghi(xx - 1, n)][baghi(yy, m)] == '.') {
    gx = -xx + x + xx - 1;
    gy = -yy + y + yy;
    if (!mo(st[baghi(gx, n)][baghi(gy, m)], gx, gy)) {
      if (st[baghi(gx, n)][baghi(gy, m)].first != sa) {
        return 1;
      }
      st[baghi(gx, n)][baghi(gy, m)] = make_pair(gx, gy);
      if (dfs(gx, gy)) {
        return 1;
      }
    }
  }
  if (s[baghi(xx + 1, n)][baghi(yy, m)] == '.') {
    gx = -xx + x + xx + 1;
    gy = -yy + y + yy;
    if (!mo(st[baghi(gx, n)][baghi(gy, m)], gx, gy)) {
      if (st[baghi(gx, n)][baghi(gy, m)].first != sa) {
        return 1;
      }
      st[baghi(gx, n)][baghi(gy, m)] = make_pair(gx, gy);
      if (dfs(gx, gy)) {
        return 1;
      }
    }
  }
  if (s[baghi(xx, n)][baghi(yy - 1, m)] == '.') {
    gx = -xx + x + xx;
    gy = -yy + y + yy - 1;
    if (!mo(st[baghi(gx, n)][baghi(gy, m)], gx, gy)) {
      if (st[baghi(gx, n)][baghi(gy, m)].first != sa) {
        return 1;
      }
      st[baghi(gx, n)][baghi(gy, m)] = make_pair(gx, gy);
      if (dfs(gx, gy)) {
        return 1;
      }
    }
  }
  if (s[baghi(xx, n)][baghi(yy + 1, m)] == '.') {
    gx = -xx + x + xx;
    gy = -yy + y + yy + 1;
    if (!mo(st[baghi(gx, n)][baghi(gy, m)], gx, gy)) {
      if (st[baghi(gx, n)][baghi(gy, m)].first != sa) {
        return 1;
      }
      st[baghi(gx, n)][baghi(gy, m)] = make_pair(gx, gy);
      if (dfs(gx, gy)) {
        return 1;
      }
    }
  }
  return 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  pair<int, int> ggg;
  ggg.first = sa;
  ggg.second = sa;
  for (int i = 0; i < 1509; i++) {
    for (int j = 0; j < 1509; j++) {
      st[i][j] = ggg;
    }
  }
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  int sx, sy;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (s[i][j] == 'S') {
        sx = i;
        sy = j;
        break;
      }
    }
  }
  s[sx][sy] = '.';
  st[sx][sy] = make_pair(sx, sy);
  if (dfs(sx, sy)) {
    cout << "Yes";
    return 0;
  }
  cout << "No";
  return 0;
}
