using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().run();
        return 0;
    }


    int[] vy = new int[] { 1, 0, -1, 0 };
    int[] vx = new int[] { 0, 1, 0, -1 };
    int h, w;

    void run()
    {
        Scanner cin = new Scanner();
        while (true)
        {
            w = cin.nextInt() + 2;
            h = cin.nextInt() + 2;
            int[,] flag = new int[h, w];
            if (h == 2) break;

            for (int i = 0; i < h - 2; i++)
            {
                string s = Console.ReadLine();
                for (int j = 0; j < w - 2; j++)
                {
                    if (s[j] == '#') flag[i + 1, j + 1] = 1;
                    else if (s[j] == '&') flag[i + 1, j + 1] = 2;
                }
            }
            Queue<int> now = new Queue<int>();
            Queue<int> next = new Queue<int>();
            int[,] dist = new int[h, w];
            int MAX = 99999;
            
            for (int i = 0; i < h; i++)
            {
                for (int j = 0; j < w; j++)
                {
                    dist[i, j] = MAX;
                }
            }
            now.Enqueue(0);
            dist[0, 0] = 0;

            int ret = MAX;
            while (ret == MAX)
            {
                while (now.Count != 0)
                {
                    int nowp = now.Dequeue();
                    int y = nowp / w;
                    int x = nowp % w;
                    //Console.WriteLine("now: " + y + " " + x);
                    for (int k = 0; k < 4; k++)
                    {
                        int ny = y + vy[k];
                        int nx = x + vx[k];
                        if (!ok(ny, nx)) continue;
                        if (dist[ny, nx] != MAX) continue;
                        if (flag[ny, nx] == 1)
                        {
                            dist[ny, nx] = dist[y, x] + 1;
                            next.Enqueue(ny * w + nx);
                        }
                        else
                        {
                            dist[ny, nx] = dist[y, x];
                            if (flag[ny, nx] == 2) ret = dist[ny, nx];
                            now.Enqueue(ny * w + nx);
                        }
                    }

                }
                now = next;
                next = new Queue<int>();
            }
            Console.WriteLine(ret);
        }

    }

    bool ok(int y, int x)
    {
        return y >= 0 && y < h && x >= 0 && x < w;
    }

}

class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        s = Console.ReadLine().Split(cs, StringSplitOptions.RemoveEmptyEntries);
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

}