#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(int i=(n);i<(k);i++)
#define ALL(a) (a).begin(),(a).end()
ll ans = 0;
void Main(){
    int n, m;
    cin >> n >> m;
    vector<int> a(m);
    For(i,0,m) cin >> a[i];
    a.push_back(0);
    a.push_back(n+1);
    m += 2;
    sort(ALL(a));
    int k = n + 1;
    For(i,0,m-1){
        if(a[i] + 1 == a[i+1]) continue;
        k = min(k, a[i+1] - a[i] - 1);
    }
    For(i,0,m-1){
        ans += (a[i+1] - a[i] - 1 + k - 1) / k;
    }
    cout << ans << endl;
}
int main(){
    Main();
    /*
    東方風神録は神が出てくるので当然神ゲー
    */
    return 0;
}

/**
 *    Coded by : lucky_21
 *               --------Lokesh Singh
**/

#include<bits/stdc++.h>
using namespace std;

#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

#define     F           first
#define     S           second
#define     pb          push_back
#define     lb          lower_bound
#define     ub          upper_bound
#define     pii         pair<int,int>
#define     all(x)      x.begin(),x.end()
#define     fix         fixed<<setprecision(10)
#define     rep(i,a,b)  for(int i=int(a);i<=int(b);i++)
#define     repb(i,b,a) for(int i=int(b);i>=int(a);i--)
#define     FastIO      ios_base::sync_with_stdio(0),cin.tie(0)

typedef double db;
typedef long long ll;

const int N=2005;
const int mod=1e9+7;

int h,w,dis[N][N];
vector<pii>v[26];
char g[N][N];
bool inside(int x,int y){
    if(g[x][y]=='#') return 0;
    if(x>0 and y>0 and x<=h and y<=w) return 1;
    return 0;
}
int bfs(pii p){
    queue<pii>q;
    q.push(p);
    rep(i,1,h) rep(j,1,w) dis[i][j]=1e9;
    dis[p.F][p.S]=0;
    while(!q.empty()){
        p=q.front();
        q.pop();
        if(g[p.F][p.S]=='G') return dis[p.F][p.S];
        if(islower(g[p.F][p.S])){
            for(pii t:v[g[p.F][p.S]-'a']) if(t!=p and dis[t.F][t.S]>dis[p.F][p.S]+1){
                q.push(t);
                dis[t.F][t.S]=dis[p.F][p.S]+1;
            }
            v[g[p.F][p.S]-'a'].clear();
        }
        rep(i,-1,1) rep(j,-1,1) if(abs(i)+abs(j)<=1 and dis[p.F+i][p.S+j]>dis[p.F][p.S]+1 and inside(p.F+i,p.S+j)){
            dis[p.F+i][p.S+j]=dis[p.F][p.S]+1;
            q.push({p.F+i,p.S+j});
        }
    }
    return -1;
}
signed main(){
    FastIO;
    cin>>h>>w;
    pii st;
    rep(i,1,h) rep(j,1,w){
        cin>>g[i][j];
        if(islower(g[i][j])) v[g[i][j]-'a'].pb({i,j});
        if(g[i][j]=='S') st={i,j};
    }
    cout<<bfs(st);
    return 0;
}
