Problem: A famous Berland's painter Kalevitch likes to shock the public. One of his last obsessions is chess. For more than a thousand years people have been playing this old game on uninteresting, monotonous boards. Kalevitch decided to put an end to this tradition and to introduce a new attitude to chessboards.

As before, the chessboard is a square-checkered board with the squares arranged in a 8 × 8 grid, each square is painted black or white. Kalevitch suggests that chessboards should be painted in the following manner: there should be chosen a horizontal or a vertical line of 8 squares (i.e. a row or a column), and painted black. Initially the whole chessboard is white, and it can be painted in the above described way one or more times. It is allowed to paint a square many times, but after the first time it does not change its colour any more and remains black. Kalevitch paints chessboards neatly, and it is impossible to judge by an individual square if it was painted with a vertical or a horizontal stroke.

Kalevitch hopes that such chessboards will gain popularity, and he will be commissioned to paint chessboards, which will help him ensure a comfortable old age. The clients will inform him what chessboard they want to have, and the painter will paint a white chessboard meeting the client's requirements.

It goes without saying that in such business one should economize on everything — for each commission he wants to know the minimum amount of strokes that he has to paint to fulfill the client's needs. You are asked to help Kalevitch with this task.

Input

The input file contains 8 lines, each of the lines contains 8 characters. The given matrix describes the client's requirements, W character stands for a white square, and B character — for a square painted black.

It is guaranteed that client's requirments can be fulfilled with a sequence of allowed strokes (vertical/column or horizontal/row).

Output

Output the only number — the minimum amount of rows and columns that Kalevitch has to paint on the white chessboard to meet the client's requirements.

Examples

Input

WWWBWWBW
BBBBBBBB
WWWBWWBW
WWWBWWBW
WWWBWWBW
WWWBWWBW
WWWBWWBW
WWWBWWBW


Output

3


Input

WWWWWWWW
BBBBBBBB
WWWWWWWW
WWWWWWWW
WWWWWWWW
WWWWWWWW
WWWWWWWW
WWWWWWWW


Output

1

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
inline int readInt() {
  int x;
  scanf("%d", &x);
  return x;
}
const double EPS = 1E-8;
const int INF = 100000000;
struct Edge {
  int to, from;
  long long cost;
  Edge(int from, int to, long long cost) : from(from), to(to), cost(cost) {}
};
class UnionFind {
 public:
  vector<long long> par;
  vector<long long> siz;
  UnionFind(long long sz_) : par(sz_), siz(sz_, 1LL) {
    for (long long i = 0; i < sz_; ++i) par[i] = i;
  }
  void init(long long sz_) {
    par.resize(sz_);
    siz.assign(sz_, 1LL);
    for (long long i = 0; i < sz_; ++i) par[i] = i;
  }
  long long root(long long x) {
    while (par[x] != x) {
      x = par[x] = par[par[x]];
    }
    return x;
  }
  bool merge(long long x, long long y) {
    x = root(x);
    y = root(y);
    if (x == y) return false;
    if (siz[x] < siz[y]) swap(x, y);
    siz[x] += siz[y];
    par[y] = x;
    return true;
  }
  bool issame(long long x, long long y) { return root(x) == root(y); }
  long long size(long long x) { return siz[root(x)]; }
};
vector<vector<Edge>> graph;
long long mod_pow(long long x, long long n, long long mod) {
  long long res = 1;
  bool c = false;
  while (n) {
    if (n & 1) res = res * x;
    if (res > mod) {
      c = true;
      res %= mod;
    }
    x = x * x % mod;
    n >>= 1;
  }
  if (c) return mod;
  return res;
}
bool sieve[5000000 + 10];
void make_sieve() {
  for (int i = 0; i < 5000000 + 10; ++i) sieve[i] = true;
  sieve[0] = sieve[1] = false;
  for (int i = 2; i * i < 5000000 + 10; ++i)
    if (sieve[i])
      for (int j = 2; i * j < 5000000 + 10; ++j) sieve[i * j] = false;
}
bool isprime(long long n) {
  if (n == 0 || n == 1) return false;
  for (long long i = 2; i * i <= n; ++i)
    if (n % i == 0) return false;
  return true;
}
template <typename T>
vector<T> gauss_jordan(const vector<vector<T>>& A, const vector<T>& b) {
  int n = A.size();
  vector<vector<T>> B(n, vector<T>(n + 1));
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      B[i][j] = A[i][j];
    }
  }
  for (int i = 0; i < n; ++i) B[i][n] = b[i];
  for (int i = 0; i < n; ++i) {
    int pivot = i;
    for (int j = i; j < n; ++j) {
      if (abs(B[j][i]) > abs(B[pivot][i])) pivot = j;
    }
    swap(B[i], B[pivot]);
    if (abs(B[i][i]) < EPS) return vector<T>();
    for (int j = i + 1; j <= n; ++j) B[i][j] /= B[i][i];
    for (int j = 0; j < n; ++j) {
      if (i != j) {
        for (int k = i + 1; k <= n; ++k) B[j][k] -= B[i][j] * B[i][k];
      }
    }
  }
  vector<T> x(n);
  for (int i = 0; i < n; ++i) x[i] = B[i][n];
  return x;
}
long long GCD(long long a, long long b) {
  if (a < b) swap(a, b);
  if (b == 0) return a;
  return GCD(b, a % b);
}
vector<vector<long long>> mul(vector<vector<long long>>& A,
                              vector<vector<long long>>& B) {
  vector<vector<long long>> C(A.size(), vector<long long>((int)B[0].size()));
  for (int i = 0; i < A.size(); ++i) {
    for (int k = 0; k < B.size(); ++k) {
      for (int j = 0; j < B[0].size(); ++j) {
        C[i][j] = (C[i][j] + A[i][k] * B[k][j] % 1000000007) % 1000000007;
      }
    }
  }
  return C;
}
vector<vector<long long>> mat_pow(vector<vector<long long>> A, long long n) {
  vector<vector<long long>> B(A.size(), vector<long long>((int)A.size()));
  for (int i = 0; i < A.size(); ++i) {
    B[i][i] = 1;
  }
  while (n > 0) {
    if (n & 1) B = mul(B, A);
    A = mul(A, A);
    n >>= 1;
  }
  return B;
}
bool operator<(const pair<int, int>& a, const pair<int, int>& b) {
  if (a.first == b.first) return a.second < b.second;
  return a.first < b.first;
}
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % 1000000007;
    inv[i] = 1000000007 - inv[1000000007 % i] * (1000000007 / i) % 1000000007;
    finv[i] = finv[i - 1] * inv[i] % 1000000007;
  }
}
long long COM(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % 1000000007) % 1000000007;
}
int bit[1000010];
int sum(int i) {
  int s = 0;
  while (i > 0) {
    s += bit[i];
    i -= i & -i;
  }
  return s;
}
void add(int i, int x) {
  while (i <= 1000010) {
    bit[i] += x;
    i += i & -i;
  }
}
long long extGCD(long long a, long long b, long long& x, long long& y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  long long d = extGCD(b, a % b, y, x);
  y -= a / b * x;
  return d;
}
vector<vector<pair<int, int>>> G(110);
int ans[110];
void dfs(int v, int c) {
  if (G[v].size() == 0) {
    ans[v] += c;
    return;
  }
  for (auto e : G[v]) {
    int u = e.first;
    int need = e.second;
    dfs(u, c * need);
  }
}
vector<string> v;
bool used[8][8];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  for (int i = 0; i < (int)8; ++i) {
    string str;
    cin >> str;
    v.push_back(str);
  }
  for (int i = 0; i < (int)8; ++i)
    for (int j = 0; j < (int)8; ++j) used[i][j] = false;
  int cnt = 0;
  for (int i = 0; i < 8; i++) {
    bool c = true;
    for (int j = 0; j < 8; j++) {
      if (v[i][j] == 'W') c = false;
    }
    if (c) {
      cnt++;
      for (int j = 0; j < 8; j++) {
        used[i][j] = true;
      }
    }
  }
  for (int i = 0; i < 8; i++) {
    bool c = true;
    for (int j = 0; j < 8; j++) {
      if (v[j][i] == 'W') c = false;
    }
    bool j2 = true;
    for (int j = 0; j < 8; j++) {
      j2 &= used[j][i];
    }
    if (c && !j2) cnt++;
  }
  cout << cnt << endl;
  return 0;
}