#include <bits/stdc++.h>
#pragma GCC target("arch=skylake-avx512")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<long, int>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rrep(i, n) for (int i = 1; i < (int)(n+1); ++i)
const long long INF = 1LL<<60;
const long long MOD = 1000000007;
const long long mod = 998244353;
const long long MAX = 510000;
int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
struct Edge {
    long long to;
    long long cost;
    Edge(long long t, long long w) : to(t), cost(w){}
};
using Graph = vector<vector<Edge>>;
/* dijkstra(G,s,dis)
    入力：グラフ G, 開始点 s, 距離を格納する dis
    計算量：O(|E|log|V|)
    副作用：dis が書き換えられる
*/
vector<ll>dis;
void dijkstra(const Graph &G, int s, vector<long long> &dis) {
    int N = G.size();
    dis.resize(N, INF);
    priority_queue<P, vector<P>, greater<P>> pq;  // 「仮の最短距離, 頂点」が小さい順に並ぶ
    dis[s] = 0;
    pq.emplace(dis[s], s);
    while (!pq.empty()) {
        P p = pq.top();
        pq.pop();
        int v = p.second;
        if (dis[v] < p.first) {  // 最短距離で無ければ無視
            continue;
        }
        for (auto &e : G[v]) {
            if (dis[e.to] > dis[v] + e.cost) {  // 最短距離候補なら priority_queue に追加
                dis[e.to] = dis[v] + e.cost;
                pq.emplace(dis[e.to], e.to);
            }
        }
    }
}
int main() {
    int H=ri(),W=ri();
    char A[H+2][W+2];
    rep(i,H+2){
        rep(j,W+2){
            A[i][j]='#';
        }
    }
    int sx=0;
    int sy=0;
    int gx=0;
    int gy=0;
    rrep(i,H){
        rrep(j,W){
            cin>>A[i][j];
            if(A[i][j]=='S'){
                sx=i-1;
                sy=j-1;
            }
            if(A[i][j]=='G'){
                gx=i-1;
                gy=j-1;
            }
        }
    }
    Graph G(H*W+26);
    vector<ll>P(26,INF);
    rrep(i,H){
        rrep(j,W){
            if(A[i][j]!='#'&&A[i+1][j]!='#'){
                G[(i-1)*W+j-1].push_back(Edge{i*W+j-1,1});
            }
            if(A[i][j]!='#'&&A[i-1][j]!='#'){
                G[(i-1)*W+j-1].push_back(Edge{(i-2)*W+j-1,1});
            }
            if(A[i][j]!='#'&&A[i][j+1]!='#'){
                G[(i-1)*W+j-1].push_back(Edge{(i-1)*W+j,1});
            }
            if(A[i][j]!='#'&&A[i][j-1]!='#'){
                G[(i-1)*W+j-1].push_back(Edge{(i-1)*W+j-2,1});
            }
        }
    }
    rrep(i,H){
        rrep(j,W){
          	if(A[i][j]!='S'&&A[i][j]!='G'){
            if(A[i][j]!='.'&&A[i][j]!='#'){
                ll Y=A[i][j]-'a';
                G[(i-1)*W+j-1].push_back(Edge{H*W+Y,1});
                G[H*W+Y].push_back(Edge{(i-1)*W+j-1,0});
            }
            }
        }
    }
    dijkstra(G,sx*W+sy,dis);
    if(dis[gx*W+gy]<INF){
    cout<<dis[gx*W+gy]<<endl;
    }
    else{
    cout<<-1<<endl;
    }
}
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(v) begin(v), end(v)
#define sz(v) v.size()
#define INF 1e18+9
#define EPSILON 1e-14
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

ll com2(ll x){
    if(x < 2){
        return 0;
    }
    return x * (x - 1) / 2;
}

ll N;

ll cake_num(ll x){ //合計がxのケーキは何個あるか
    return com2(x-1) - com2(x-1-N) * 3 + com2(x-1-2*N) * 3 - com2(x-1-3*N);
}

ll cake_num2(ll x, ll y){ //合計がxで綺麗さがyのケーキは何個あるか
    if(y <= 0 || y >= x-1 || y >= N+1 || y + 2*N < x){
        return 0;
    }
    x -= y;
    ll lb = max(x-N, 1LL);
    ll ub = min(N, x-1);
    return ub - lb + 1;
}

int main()
{
    ll K;
    cin >> N >> K;
    ll cnt = 0;
    ll p = 2;
    while(cnt < K){
        p++;
        cnt += cake_num(p);
    }
    cnt -= cake_num(p);
    ll q = 0;
    while(cnt < K){
        q++;
        cnt += cake_num2(p, q);
    }
    cnt -= cake_num2(p, q);
    ll r = max(p-q-N, 1LL) - 1;
    r += K - cnt;
    cout << q << " " << r << " " << p-q-r << '\n';
}