#include <stdio.h>
const int N=110;
const int INF=1<<30;
int min(int a,int b){
    return a>b?b:a;
}
int main(){
    int n,dp[N][N],a[N];
    scanf("%d%d%d",&n,&a[0],&a[1]);
    for(int i=1;i<n;i++)scanf("%d%d",&a[i],&a[i+1]);
    for(int k=1;k<n;k++){
        for(int i=0;i<n-k;i++){
            dp[i][i+k]=INF;
            for(int j=i;j<i+k;j++)dp[i][i+k]=min(dp[i][i+k],dp[i][j]+dp[j+1][i+k]+a[i]*a[j+1]*a[i+k+1]);
        }
    }
    printf("%d\n",dp[0][n-1]);
}

#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;

int main(){
  
  int H, W, i, j, k;
  cin >> H >> W;
  vector<vector<char>> A(H, vector<char>(W));
  vector<int> dx = {0, 1, 0, -1}, dy = {1, 0, -1, 0};
  queue<P> nxs;
  
  int cnt_sn = 0; //シャープの数
  int cnt_fn = 0; //フェイズ内の要素の数
  int cnt    = 0; // フェイズの数
  for(i = 0; i < H; i++){
    for(j = 0; j < W; j++){
      cin >> A.at(i).at(j);
      if(A.at(i).at(j) == '#'){
        nxs.push(P(i, j));
        cnt_sn++;
      }
    }
  }
  
  while(nxs.size() != 0 && cnt_sn < W * H){
     
    if(cnt_fn == 0){
      cnt++; cnt_fn = nxs.size();
    }
    P pos = nxs.front(); nxs.pop();
    for(i = 0; i < 4; i++){
      int x = pos.second + dx.at(i), y = pos.first + dy.at(i);
      if(x >= 0 && y >= 0 && x < W && y < H){
        if(A.at(y).at(x) == '.'){
          A.at(y).at(x) = '#';
          cnt_sn++;
          nxs.push(P(y, x));
        }
      }
    }
    cnt_fn--;
  }
  
  cout << cnt << endl;
  return 0;
}