#include <bits/stdc++.h>
using namespace std;
char a[1510][1510];
int check[1510][1510];
int n, m;
int xs, ys;
pair<int, int> seen[1510][1510];
pair<int, int> d[4];
void make(pair<int, int> d[]) {
  for (int i = 0; i < 4; i++) {
    if (i == 0) {
      d[i].first = 0;
      d[i].second = 1;
    } else if (i == 1) {
      d[i].first = 0;
      d[i].second = -1;
    } else if (i == 2) {
      d[i].first = 1;
      d[i].second = 0;
    } else {
      d[i].first = -1;
      d[i].second = 0;
    }
  }
}
bool flag = 0;
int tabdil(int o, int o1) {
  while (o < 0) o += o1;
  return o % (o1);
}
void dfs(int x, int y) {
  if (flag) return;
  int b[2] = {};
  b[0] = tabdil(x, n);
  b[1] = tabdil(y, m);
  pair<int, int> save;
  save.first = x;
  save.second = y;
  if (a[b[0]][b[1]] != '#') {
    if (check[b[0]][b[1]] != 0 && seen[b[0]][b[1]] == save) return;
    seen[b[0]][b[1]].first = x;
    seen[b[0]][b[1]].second = y;
    check[b[0]][b[1]]++;
    if (check[b[0]][b[1]] > 1) {
      cout << "YES";
      flag = true;
      return;
    }
    for (int i = 0; i < 4; i++) dfs(x + d[i].first, y + d[i].second);
  }
}
int main() {
  make(d);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
      if (a[i][j] == 'S') {
        xs = i;
        ys = j;
      }
    }
  }
  dfs(xs, ys);
  if (!flag) cout << "NO";
}
