#include <bits/stdc++.h>
using namespace std;
const long long MOD = (1e9) + 7;
const int INF = 1e9;
const long long INF64 = 1e18;
const double EPS = 1e-12;
const double PI = acos(-1);
const long long MD = 6235164;
const long long T = 23917;
const int N = 400100;
const int M = 1510;
int n, m, first, second;
string a[M];
bool use[M][M];
pair<int, int> mark[M][M];
void dfs(int first, int second) {
  int xx = (first + n * 1500) % n, yy = (second + m * 1500) % m;
  use[xx][yy] = 1;
  mark[xx][yy] = make_pair(first, second);
  for (int i = -1; i <= 1; i++)
    for (int j = -1; j <= 1; j++)
      if (abs(i) + abs(j) == 1) {
        int xx = first + i, yy = second + j;
        int x1 = (xx + n * 1500) % n, y1 = (yy + m * 1500) % m;
        if (a[x1][y1] == '#') continue;
        if (!use[x1][y1])
          dfs(xx, yy);
        else if (mark[x1][y1] != make_pair(xx, yy)) {
          cout << "Yes";
          exit(0);
        }
      }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m;
  for (int i = 0; i < int(n); i++) {
    cin >> a[i];
    for (int j = 0; j < int(m); j++)
      if (a[i][j] == 'S') {
        first = i;
        second = j;
        a[i][j] = '.';
        break;
      }
  }
  dfs(first, second);
  cout << "No";
  return 0;
}
