#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define reps(i,s,n) for(int i=s;i<n;++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int M = 1e5;
int main()
{
    int n;
    cin >> n;
    vector<int> t(n);
    rep(i, n) cin >> t[i];
    int sum = 0;
    rep(i, n) sum += t[i];

    //for文でMまで探索するので、M+1000でもはみ出さないようにする。
    vector<vector<int>> dp(n + 5, vector<int>(M+1005));

    dp[0][0] = 1;
    rep(i, n)
    {
        rep(j, M)
        {
            dp[i + 1][j] = dp[i][j] | dp[i + 1][j];
            dp[i + 1][j + t[i]] = dp[i][j] | dp[i + 1][j + t[i]];
        }
    }
    int ans = M;
    rep(i, M)
    {
        if (dp[n][i] == 1)
        {
            int a = i;
            int b = sum - i;
            ans = min(ans, max(a, b));
        }
    }
    cout << ans << endl;

    return 0;
}

/*
                    __
                   /\ \
 _ __   ___     ___\ \ \/'\     ___      __      ___     ___      __
/\`'__\/ __`\  /'___\ \ , <    / __`\  /'__`\  /' _ `\ /' _ `\  /'__`\
\ \ \//\ \L\ \/\ \__/\ \ \\`\ /\ \L\ \/\ \L\.\_/\ \/\ \/\ \/\ \/\ \L\.\_
 \ \_\\ \____/\ \____\\ \_\ \_\ \____/\ \__/.\_\ \_\ \_\ \_\ \_\ \__/.\_\
  \/_/ \/___/  \/____/ \/_/\/_/\/___/  \/__/\/_/\/_/\/_/\/_/\/_/\/__/\/_/


*/

#ifndef __AHA__HEADER
#define __AHA__HEADER

#include <bits/stdc++.h>
using namespace std;
#define g0 get<0>
#define g1 get<1>
#define g2 get<2>
#define ft first
#define sd second
#define sz(x) (i6) x.size()
#define psb(x) push_back(x)
#define ppb() pop_back()
#define bg(x) x.begin()
#define ed(x) x.end()
#define col(x) x.begin(), x.end()
#define srt(x) sort(x.begin(), x.end())
#define vec vector
#define deq deque
#define hmap unordered_map
#define pq priority_queue
#define fn function
#ifdef LOCAL
#define git stauDBG_MACRO_NO_WARNING
#include <dbg.h>
#define dbgt dbg(dbg::time())
#else
#define dbg(...)
#define dbgt
#endif
typedef string str;
typedef int32_t i3;
typedef int64_t i6;
typedef int64_t i64;
typedef uint32_t u3;
typedef uint64_t u6;
typedef long double d6;
typedef pair<i6, i6> p6;
typedef vec<i6> vi6;
typedef vec<p6> vp6;
typedef vec<bool> vb;
typedef vec<vi6> vv;
typedef deq<p6> dp6;
typedef deq<i6> di6;
typedef map<i6, i6> mi6;
typedef map<p6, i6> mp6;
typedef set<i6> si6;
typedef hmap<i6, i6> hi6;
typedef vv graph;
typedef vv matrix;

const i6 INF = INT64_MAX / 4;
const i6 NINF = -INF;
const i6 ZERO = 0;
const i6 ONE = 1;

#endif

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
#ifdef LOCAL
  ifstream cin{"input.txt"};
  ofstream cout{"output.txt"};
#endif

  i64 h, w;
  cin >> h >> w;

  vv v(h, vi6(w));
  for (i64 i = 0; i < h; i++) {
    string s;
    cin >> s;
    for (i64 j = 0; j < w; j++) {
      if (s[j] == '.') {
        v[i][j] = 0;
      } else {
        v[i][j] = 1;
      }
    }
  }

  i64 res = 0;

  for (i64 i = 1; i < h; i++) {
    for (i64 j = 1; j < w; j++) {
      i64 x = 0;
      if (v[i][j - 1] == 0) {
        x += 1;
      }
      if (v[i - 1][j - 1] == 0) {
        x += 1;
      }
      if (v[i - 1][j] == 0) {
        x += 1;
      }
      if (v[i][j] == 0) {
        x += 1;
      }

      if (x % 2 == 1) {
        res += 1;
      }
    }
  }

  cout << res << endl;

  return 0;
}
