#include <bits/stdc++.h>
using namespace std;
const int maxn = 1500 + 10;
const long long inf = 1e18;
char s[maxn][maxn];
pair<int, int> ame[maxn][maxn];
int n, m;
bool valid(int x, int y) {
  x = (n + x % n) % n;
  y = (m + y % m) % m;
  ;
  return (s[x][y] == '.' || s[x][y] == 'S');
}
void dfs(int x, int y) {
  int amex = (n + x % n) % n, amey = (m + y % m) % m;
  if (ame[amex][amey].first == -85008500)
    ame[amex][amey].first = x, ame[amex][amey].second = y;
  else if (ame[amex][amey].first == x && ame[amex][amey].second == y)
    return;
  else {
    cout << "Yes" << endl;
    exit(0);
  }
  for (int i = -1; i < 2; i++) {
    for (int j = -1; j < 2; j++) {
      if ((i == 0 || j == 0) && (i || j)) {
        if (valid(x + i, y + j) == 1) dfs(x + i, y + j);
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  string second;
  for (int i = 0; i < n; i++) {
    cin >> second;
    for (int j = 0; j < m; j++) s[i][j] = second[j];
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) ame[i][j].first = ame[i][j].second = -85008500;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (s[i][j] == 'S') dfs(i, j);
  cout << "No" << endl;
  return 0;
}
