#include <bits/stdc++.h>
#pragma warning(disable : 4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;
inline long long gcd(long long a, long long b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
inline long long power(long long a, long long n, long long m) {
  if (n == 0) return 1;
  long long p = power(a, n / 2, m);
  p = (p * p) % m;
  if (n % 2)
    return (p * a) % m;
  else
    return p;
}
const long long MOD = 1000000007;
const int INF = 10000000;
const long long LL_INF = 0x3f3f3f3f3f3f3f3f;
bool p1 = 0;
pair<int, int> visited[2000][2000];
int st;
int n, m;
void dfs(int x, int y, string s[]) {
  if (p1) return;
  int x1, y1;
  x1 = x - 1;
  y1 = y;
  int x2, y2;
  x2 = visited[x][y].first;
  y2 = visited[x][y].second;
  if (x1 < 0) {
    --x2;
    x1 += n;
  }
  if (x1 >= n) {
    ++x2;
    x1 -= n;
  }
  if (y1 < 0) {
    --y2;
    y1 += m;
  }
  if (y1 >= m) {
    ++y2;
    y1 -= m;
  }
  if (s[x1][y1] != '#' && visited[x1][y1] == make_pair(-INF, -INF)) {
    visited[x1][y1] = make_pair(x2, y2);
    dfs(x1, y1, s);
  } else if (s[x1][y1] != '#' && visited[x1][y1] != make_pair(x2, y2)) {
    p1 = 1;
    return;
  }
  x1 = x + 1;
  y1 = y;
  x2 = visited[x][y].first;
  y2 = visited[x][y].second;
  if (x1 < 0) {
    --x2;
    x1 += n;
  }
  if (x1 >= n) {
    ++x2;
    x1 -= n;
  }
  if (y1 < 0) {
    --y2;
    y1 += m;
  }
  if (y1 >= m) {
    ++y2;
    y1 -= m;
  }
  if (s[x1][y1] != '#' && visited[x1][y1] == make_pair(-INF, -INF)) {
    visited[x1][y1] = make_pair(x2, y2);
    dfs(x1, y1, s);
  } else if (s[x1][y1] != '#' && visited[x1][y1] != make_pair(x2, y2)) {
    p1 = 1;
    return;
  }
  x1 = x;
  y1 = y - 1;
  x2 = visited[x][y].first;
  y2 = visited[x][y].second;
  if (x1 < 0) {
    --x2;
    x1 += n;
  }
  if (x1 >= n) {
    ++x2;
    x1 -= n;
  }
  if (y1 < 0) {
    --y2;
    y1 += m;
  }
  if (y1 >= m) {
    ++y2;
    y1 -= m;
  }
  if (s[x1][y1] != '#' && visited[x1][y1] == make_pair(-INF, -INF)) {
    visited[x1][y1] = make_pair(x2, y2);
    dfs(x1, y1, s);
  } else if (s[x1][y1] != '#' && visited[x1][y1] != make_pair(x2, y2)) {
    p1 = 1;
    return;
  }
  x1 = x;
  y1 = (y + 1);
  x2 = visited[x][y].first;
  y2 = visited[x][y].second;
  if (x1 < 0) {
    --x2;
    x1 += n;
  }
  if (x1 >= n) {
    ++x2;
    x1 -= n;
  }
  if (y1 < 0) {
    --y2;
    y1 += m;
  }
  if (y1 >= m) {
    ++y2;
    y1 -= m;
  }
  if (s[x1][y1] != '#' && visited[x1][y1] == make_pair(-INF, -INF)) {
    visited[x1][y1] = make_pair(x2, y2);
    dfs(x1, y1, s);
  } else if (s[x1][y1] != '#' && visited[x1][y1] != make_pair(x2, y2)) {
    p1 = 1;
    return;
  }
}
int main() {
  cin >> n >> m;
  int x, y;
  string s[n];
  for (int i = 0; i < 2000; i++)
    for (int j = 0; j < 2000; j++) visited[i][j] = make_pair(-INF, -INF);
  for (int i = 0; i < n; i++) cin >> s[i];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (s[i][j] == 'S') {
        x = i;
        y = j;
        visited[i][j] = make_pair(0, 0);
        break;
      }
    }
  }
  dfs(x, y, s);
  if (p1)
    cout << "Yes";
  else
    cout << "No";
  cout << endl;
  return 0;
}
