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

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

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

        public int CompareTo(object obj)
        {
            State other = (State)obj;
            return other.cnt - cnt;         //rev
        }
    }

    class Problem
    {
        readonly int[] moveX = new int[] { -1, 0, 1, 0 };
        readonly int[] moveY = new int[] { 0, -1, 0, 1 };

        readonly int w, h;

        int[,] map;
        bool[,] visited;

        int sx, sy, minCnt;

        public Problem(int w, int h)
        {
            this.w = w;
            this.h = h;
            map = new int[h, w];
            visited = new bool[h, w];
            minCnt = int.MaxValue;
        }

        public int Solve()
        {
            MakeMap();

            PriorityQueue<State> PQ = new PriorityQueue<State>();
            PQ.Enqueue(new State(sx, sy, 0));

            while (PQ.Count > 0)
            {
                State cur = PQ.Dequeue();
                visited[cur.y, cur.x] = true;

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

                    if (IsValid(nextX, nextY))
                    {
                        if (visited[nextY, nextX]) continue;

                        int tempCnt = cur.cnt + map[nextY, nextX];

                        if (tempCnt < minCnt)
                        {
                            PQ.Enqueue(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;
                    }
                }
            }
        }
    }

    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);
        }
    }

    class PriorityQueue<T> where T : IComparable
    {
        List<T> heap;
        int size;

        public PriorityQueue()
        {
            heap = new List<T>();
        }

        public int Count { get { return size; } }

        public void Enqueue(T x)
        {
            heap.Add(x);
            int i = size++;

            while (i > 0)
            {
                int p = (i - 1) / 2;

                if (Compare(heap[p], x) <= 0) break;

                heap[i] = heap[p];
                i = p;
            }
            heap[i] = x;
        }

        public T Dequeue()
        {
            T ret = heap[0];
            T x = heap[--size];

            int i = 0;
            while (i * 2 + 1 < size)
            {
                int a = i * 2 + 1;
                int b = i * 2 + 2;

                if (b < size && Compare(heap[b], heap[a]) < 0)
                    a = b;
                if (Compare(heap[a], x) >= 0)
                    break;

                heap[i] = heap[a];
                i = a;
            }
            heap[i] = x;
            heap.RemoveAt(size);
            return ret;
        }

        private int Compare(T x, T y)
        {
            return y.CompareTo(x);
        }
    }
}