#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MAX_INF 0x3f
#define MAX_INF_VAL 0x3f3f3f3f

using namespace std;

bool good;
int n, m;
char s[ 2100 ][ 2100 ];
int fuck_x[ 2100 ][ 2100 ], fuck_y[ 2100 ][ 2100 ];
int movex[] = { 0, -1, 0, 1 };
int movey[] = { -1, 0, 1, 0 };

queue< pair< int, int > > q;

void dfs( int, int );

int main()
{
    int x, y;
    for(int k = 1; k <= 17; ++k)
    {
        string s1, s2;
        s1.append("data/data"+to_string(k));
        s1.append(".in");
        s2.append("data/data"+to_string(k));
        s2.append(".out");
        freopen(s1.data(), "r", stdin);
        freopen(s2.data(), "w", stdout);
        scanf( "%d%d", &n, &m );
        for( int i = 0; i < n; ++i )
        {
            scanf( "%s", s[ i ] );
            //printf("%s\n", s[i]);
            for( int j = 0; j < m; ++j )
            {
                fuck_x[ i ][ j ] = fuck_y[ i ][ j ] = 99999999;
                if( s[ i ][ j ] == 'S' )
                {
                    x = i, y = j;
                }
            }
        }
        good = false;
        while( !q.empty() )
            q.pop();
        fuck_x[ x ][ y ] = x, fuck_y[ x ][ y ] = y;
        dfs( x, y );
        if( good )
            printf( "Yes\n" );
        else
            printf( "No\n" );
    }
}

void dfs( int xx, int yy )
{
    int x, y;
    int nx, ny, rx, ry;
    pair< int, int > p;
    q.push( make_pair( xx, yy ) );
    while( !q.empty() )
    {
        p = q.front();
        q.pop();
        x = p.first, y = p.second;
        for( int i = 0; !good && i < 4; ++i )
        {
            rx = nx = x + movex[ i ];
            ry = ny = y + movey[ i ];
            rx %= n, ry %= m;
            rx += n, ry += m;
            rx %= n, ry %= m;
            if( s[ rx ][ ry ] == '#' )
                continue;
            if( fuck_x[ rx ][ ry ] == 99999999 )
            {
                fuck_x[ rx ][ ry ] = nx;
                fuck_y[ rx ][ ry ] = ny;
                q.push( make_pair( nx, ny ) );
            }
            else if( fuck_x[ rx ][ ry ] != nx || fuck_y[ rx ][ ry ] != ny )
            {
                good = true;
                return;
            }
        }
    }
}