#include <bits/stdc++.h>
using namespace std;

int main() {
  int N;
  string S;
  cin >> N >> S;
  vector<int> A(N + 1);
  for (int i = 0; i <= N; i++) cin >> A.at(i);
  int k = 11000;
  for (int i = 0; i < N; i++) k = min(k, abs(A.at(i + 1) - A.at(i)));
  cout << k << endl;
  vector<vector<int>> B(k, vector<int>(N + 1));
  for (int i = 0; i < k; i++) {
    for (int j = 0; j <= N; j++) {
      B.at(i).at(j) = A.at(j) / k;
      if (i < A.at(j) % k) B.at(i).at(j)++;
      cout << B.at(i).at(j);
      if (j == N) cout << endl;
      else cout << " ";
    }
  }
}
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair <int, int> pin;

const int N = 1005;
const ll P = 998244353LL;

int n, m, ufs[N << 1];
bool vis[N << 1];
char s[N][N];

inline int id(int x, int y) {
    return (x - 1) * m + y;
}

int find(int x) {
    return ufs[x] == x ? x : ufs[x] = find(ufs[x]);
}

inline void merge(int x, int y) {
    int fx = find(x), fy = find(y);
    if (fx == fy) return;
    ufs[fx] = fy;
}

template <typename T>
inline void read(T &X) {
    char ch = 0; T op = 1; 
    for (X = 0; ch > '9' || ch < '0'; ch = getchar())
        if (ch == '-') op = -1;
    for (; ch >= '0' && ch <= '9'; ch = getchar())
        X = (X * 10) + ch - '0';
    X *= op;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("sample.in", "r", stdin);
    clock_t st_clock = clock();
#endif

    read(n), read(m);
    for (int i = 1; i <= n; i++) scanf("%s", s[i] + 1);
    for (int i = 1; i <= n + m; i++) ufs[i] = i;
    s[1][1] = s[1][m] = s[n][1] = s[n][m] = '#';
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
            if (s[i][j] == '#') merge(i, j + n);
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        int now = find(i);
        if (vis[now]) continue;
        vis[now] = 1;
        ++ans; 
    }
    int tmp = 0;
    memset(vis, 0, sizeof(vis));
    for (int i = n + 1; i <= n + m; i++) {
        int now = find(i);
        if (vis[now]) continue;
        vis[now] = 1;
        ++tmp;
    }
    ans = min(ans, tmp);
    --ans;
    printf("%d\n", ans);

#ifndef ONLINE_JUDGE
    clock_t ed_clock = clock();
    printf("time = %f ms\n", (double)(ed_clock - st_clock) / CLOCKS_PER_SEC * 1000);
#endif
    return 0;
}