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

namespace ConsoleApplication1
{
    struct State
    {
        internal int x, y, cnt;

        public State(int x, int y, int cnt)
        {
            this.x = x;
            this.y = y;
            this.cnt = cnt;
        }
    }

    class Problem
    {
        readonly int[] moveX = new int[] { -1, 0, 1, 0 };
        readonly int[] moveY = new int[] { 0, -1, 0, 1 };
        readonly int INF = 1 << 20;
        readonly int w, h;

        int[,] map, counts;
        int sx, sy, minCnt;

        public Problem(int w, int h)
        {
            this.w = w;
            this.h = h;
            map = new int[h, w];
            counts = new int[h, w];
        }

        public int Solve()
        {
            MakeMap();
            minCnt = INF;

            Stack<State> stk = new Stack<State>();
            stk.Push(new State(sx, sy, 0));

            while (stk.Count > 0)
            {
                State cur = stk.Pop();
                counts[cur.y, cur.x] = cur.cnt;

                for (int i = 0; i < 4; i++)
                {
                    int nextX = cur.x + moveX[i];
                    int nextY = cur.y + moveY[i];

                    if (IsValid(nextX, nextY))
                    {
                        int tempCnt = cur.cnt + (map[cur.y, cur.x] == 1 ? 0 : map[nextY, nextX]);
                        
                        if (counts[nextY, nextX] > tempCnt) stk.Push(new State(nextX, nextY, tempCnt));
                    }
                    else minCnt = Math.Min(minCnt, cur.cnt);
                }
            }
            return minCnt;
        }

        private bool IsValid(int x, int y)
        {
            if (x < 0 || x >= w) return false;
            if (y < 0 || y >= h) return false;
            return true;
        }

        private void MakeMap()
        {
            for (int i = 0; i < h; i++)
            {
                string input = Console.ReadLine();

                for (int j = 0; j < w; j++)
                {
                    switch (input[j])
                    {
                        case '#':
                            map[i, j] = 1;
                            break;
                        case '&':
                            sx = j;
                            sy = i;
                            break;
                    }
                    counts[i, j] = INF;
                }
            }
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder();

            while (true)
            {
                string[] input = Console.ReadLine().Split(' ');
                int w = int.Parse(input[0]);
                int h = int.Parse(input[1]);

                if (w == 0 && h == 0) break;

                Problem pb = new Problem(w, h);
                sb.AppendLine(pb.Solve().ToString());
            }
            Console.Write(sb);
        }
    }
}