#include <bits/stdc++.h>
using namespace std;
const int inf = 1234567890;
const long long infl = 8876543210123456789ll;
const int mod = 1000000007;
void init() {
  ios::sync_with_stdio(false);
  cin.tie(0);
}
template <class RandomAccessIterator>
void print(RandomAccessIterator a, RandomAccessIterator b) {
  for (; a < b; ++a) {
    cout << (*a) << '\n';
  }
}
template <class RandomAccessIterator>
void println(RandomAccessIterator a, RandomAccessIterator b) {
  for (; a < b; ++a) {
    cout << (*a) << ' ';
  }
  cout << '\n';
}
template <class RandomAccessIterator>
void rarr(RandomAccessIterator a, RandomAccessIterator b) {
  for (; a < b; ++a) {
    cin >> (*a);
  }
}
template <class RandomAccessIterator>
void rgraph(RandomAccessIterator a, int vert, int edj) {
  for (int i = 0; i < (edj); ++i) {
    int u, v;
    cin >> u >> v;
    a[--u].push_back(--v);
    a[v].push_back(u);
  }
}
template <class RandomAccessIterator>
void rdgraph(RandomAccessIterator a, int vert, int edj) {
  for (int i = 0; i < (edj); ++i) {
    int u, v;
    cin >> u >> v;
    a[--u].push_back(--v);
  }
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
string s[1500];
pair<int, int> v[1500][1500];
int md(int i, int m) {
  if (i >= 0) {
    return i % m;
  }
  return (m - (m - i) % m) % m;
}
int main() {
  init();
  int n, m;
  cin >> n >> m;
  rarr(s, s + n);
  int sx, sy;
  for (int i = 0; i < (n); ++i) {
    for (int j = 0; j < (m); ++j) {
      if (s[i][j] == 'S') {
        sx = j;
        sy = i;
        v[i][j] = {i, j};
      } else {
        v[i][j] = {inf, inf};
      }
    }
  }
  queue<pair<int, int> > q({v[sy][sx]});
  while (!(q).empty()) {
    pair<int, int> u = q.front();
    q.pop();
    if (s[md(u.first + 1, n)][md(u.second, m)] != '#') {
      if (v[md(u.first + 1, n)][md(u.second, m)].first == inf) {
        v[md(u.first + 1, n)][md(u.second, m)] = {u.first + 1, u.second};
        q.push({u.first + 1, u.second});
      } else if (v[md(u.first + 1, n)][md(u.second, m)] !=
                 make_pair(u.first + 1, u.second)) {
        cout << ("Yes") << '\n';
        return 0;
      }
    }
    if (s[md(u.first - 1, n)][md(u.second, m)] != '#') {
      if (v[md(u.first - 1, n)][md(u.second, m)].first == inf) {
        v[md(u.first - 1, n)][md(u.second, m)] = {u.first - 1, u.second};
        q.push({u.first - 1, u.second});
      } else if (v[md(u.first - 1, n)][md(u.second, m)] !=
                 make_pair(u.first - 1, u.second)) {
        cout << ("Yes") << '\n';
        return 0;
      }
    }
    if (s[md(u.first, n)][md(u.second + 1, m)] != '#') {
      if (v[md(u.first, n)][md(u.second + 1, m)].first == inf) {
        v[md(u.first, n)][md(u.second + 1, m)] = {u.first, u.second + 1};
        q.push({u.first, u.second + 1});
      } else if (v[md(u.first, n)][md(u.second + 1, m)] !=
                 make_pair(u.first, u.second + 1)) {
        cout << ("Yes") << '\n';
        return 0;
      }
    }
    if (s[md(u.first, n)][md(u.second - 1, m)] != '#') {
      if (v[md(u.first, n)][md(u.second - 1, m)].first == inf) {
        v[md(u.first, n)][md(u.second - 1, m)] = {u.first, u.second - 1};
        q.push({u.first, u.second - 1});
      } else if (v[md(u.first, n)][md(u.second - 1, m)] !=
                 make_pair(u.first, u.second - 1)) {
        cout << ("Yes") << '\n';
        return 0;
      }
    }
  }
  cout << ("No") << '\n';
}
