#include <algorithm>
#include <iostream>
#include <vector>
#include <cstdint>

int main() {
  int N;
  std::int64_t X;
  std::cin >> N >> X;
  std::vector<int> A(N);
  for (int i = 0; i < N; ++i) {
    std::cin >> A[i];
  }
  std::int64_t best = X;
  for (int k = 1; k <= N; ++k) {
    std::vector<std::vector<int>> powers(k + 1, std::vector<int>(k, -1));
    powers[0][0] = 0;
    for (const auto a : A) {
      for (int i = k - 1; i >= 0; --i) {
        for (int j = 0; j < k; ++j) {
          if (powers[i][j] >= 0) {
            const int m = (j + a) % k;
            powers[i + 1][m] = std::max(powers[i + 1][m], powers[i][j] + a);
          }
        }
      }
    }
    for (int j = 0; j < k; ++j) {
      if ((X - j) % k == 0 && powers[k][j] >= 0) {
        best = std::min(best, (X - powers[k][j]) / k);
      }
    }
  }
  std::cout << best << std::endl;
  return 0;
}

// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long; // int64_t
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

#define REP(i,m,n) for(int i = m; i <= (n); ++i)
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)

const int INF = 1e9+7;   //10oku7

const int KONS_UFT= 300000;

vector<int> par(KONS_UFT); //par 親
vector<int> depth(KONS_UFT); //depth 木の深さ

//要素を初期化
void init( int n ){
  rep (i , n){
    par[i] = i;
  }

  rep (i , n){
    depth[i] = 0;
  }

  return;
}

//木の根を調べる。
int find( int x ){
  if (par[x] == x) {
    return x;
  } else {
    return par[x] = find( par[x]);
  }
}

//xとyの属する集合を合併
void unite( int x, int y){
  x = find( x);
  y = find( y);
  if (x == y) return;

  if (depth [x] < depth [y]) {
    par[x] = y;
  } else {
    par[y] = x;
    if (depth[x] == depth [y]) depth[x]++;
  }
  return;
}

//xとyが同じ集合に属するか
bool same( int x, int y){
  return find(x) == find (y);
}

int main() {

  int H , W;
  cin >> H >> W;
  vector<string> S(H);
  rep(i,H){
    cin >> S.at(i);
  }

  S.at(0).at(0) = '#';
  S.at(0).at(W-1) = '#';
  S.at(H-1).at(0) = '#';
  S.at(H-1).at(W-1) = '#';

  init(H+W);


  rep(i,H){
    rep(j,W){
      if (S.at(i).at(j) == '#') unite(i,j+H);
    }
  }

  set<int> col, row;
  rep(i,H){
    col.insert(find(i));
  }
  rep(j,W){
    row.insert(find(j+H));
  }

  cout << min(col.size() -1 , row.size() -1) << endl;



}
