Smart Beaver is careful about his appearance and pays special attention to shoes so he has a huge number of pairs of shoes from the most famous brands of the forest. He's trying to handle his shoes carefully so that each pair stood side by side. But by the end of the week because of his very active lifestyle in his dressing room becomes a mess.

Smart Beaver from ABBYY is not only the brightest beaver in the area, but he also is the most domestically oriented. For example, on Mondays the Smart Beaver cleans everything in his home.

It's Monday morning. Smart Beaver does not want to spend the whole day cleaning, besides, there is much in to do and it’s the gym day, so he wants to clean up as soon as possible. Now the floors are washed, the dust is wiped off — it’s time to clean up in the dressing room. But as soon as the Smart Beaver entered the dressing room, all plans for the day were suddenly destroyed: chaos reigned there and it seemed impossible to handle, even in a week. Give our hero some hope: tell him what is the minimum number of shoes need to change the position to make the dressing room neat.

The dressing room is rectangular and is divided into n × m equal squares, each square contains exactly one shoe. Each pair of shoes has a unique number that is integer from 1 to <image>, more formally, a square with coordinates (i, j) contains an integer number of the pair which is lying on it. The Smart Beaver believes that the dressing room is neat only when each pair of sneakers lies together. We assume that the pair of sneakers in squares (i1, j1) and (i2, j2) lies together if |i1 - i2| + |j1 - j2| = 1.

Input

The first line contains two space-separated integers n and m. They correspond to the dressing room size. Next n lines contain m space-separated integers each. Those numbers describe the dressing room. Each number corresponds to a snicker. 

It is guaranteed that: 

  * n·m is even. 
  * All numbers, corresponding to the numbers of pairs of shoes in the dressing room, will lie between 1 and <image>. 
  * Each number from 1 to <image> will occur exactly twice. 



The input limits for scoring 30 points are (subproblem C1): 

  * 2 ≤ n, m ≤ 8. 



The input limits for scoring 100 points are (subproblems C1+C2): 

  * 2 ≤ n, m ≤ 80. 

Output

Print exactly one integer — the minimum number of the sneakers that need to change their location.

Examples

Input

2 3
1 1 2
2 3 3


Output

2


Input

3 4
1 3 2 6
2 1 5 6
4 4 5 3


Output

4

Note

<image> The second sample. 
#include <bits/stdc++.h>
using namespace std;
struct node {
  int u, v, c, w, next;
} edge[(10 * 20000)];
int tot, last[20000];
int n, m, S, T;
int g[100][100];
int dx[2] = {0, 1};
int dy[2] = {1, 0};
int dist[20000], pre[20000], visit[20000];
inline int getpt(int x, int y) { return x * m + y; }
void addedge(int u, int v, int c, int w) {
  edge[tot].u = u;
  edge[tot].v = v;
  edge[tot].c = c;
  edge[tot].w = w;
  edge[tot].next = last[u];
  last[u] = tot++;
  edge[tot].u = v;
  edge[tot].v = u;
  edge[tot].c = 0;
  edge[tot].w = -w;
  edge[tot].next = last[v];
  last[v] = tot++;
}
bool spfa(int s, int t, int n) {
  memset(dist, 0x3f, sizeof(dist[0]) * (n + 13));
  memset(visit, 0, sizeof(visit[0]) * (n + 13));
  memset(pre, -1, sizeof(pre[0]) * (n + 13));
  queue<int> q;
  while (!q.empty()) q.pop();
  q.push(s);
  visit[s] = true;
  dist[s] = 0;
  pre[s] = -1;
  while (!q.empty()) {
    int u = q.front();
    visit[u] = false;
    q.pop();
    for (int j = last[u]; j != -1; j = edge[j].next) {
      if (edge[j].c > 0 && dist[u] + edge[j].w < dist[edge[j].v]) {
        dist[edge[j].v] = dist[u] + edge[j].w;
        pre[edge[j].v] = j;
        if (!visit[edge[j].v]) {
          q.push(edge[j].v);
          visit[edge[j].v] = true;
        }
      }
    }
  }
  if (dist[t] == dist[n + 10])
    return false;
  else
    return true;
}
int ChangeFlow(int t) {
  int det = 0x7f7f, u = t;
  while (~pre[u]) {
    u = pre[u];
    det = min(det, edge[u].c);
    u = edge[u].u;
  }
  u = t;
  while (~pre[u]) {
    u = pre[u];
    edge[u].c -= det;
    edge[u ^ 1].c += det;
    u = edge[u].u;
  }
  return det;
}
int MinCostFlow(int s, int t, int n) {
  int mincost, maxflow;
  mincost = maxflow = 0;
  while (spfa(s, t, n)) {
    int det = ChangeFlow(t);
    mincost += det * dist[t];
    maxflow += det;
  }
  return mincost;
}
int main() {
  while (scanf("%d%d", &n, &m) != EOF) {
    tot = 0;
    memset(last, -1, sizeof(last));
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        scanf("%d", &g[i][j]);
      }
    }
    int x, y, u, v, a, b;
    S = n * m + 1, T = n * m + 2;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        u = getpt(i, j);
        if ((i + j) % 2 == 0) {
          addedge(S, u, 1, 0);
        } else {
          addedge(u, T, 1, 0);
        }
        for (int k = 0; k < 2; k++) {
          a = i + dx[k];
          b = j + dy[k];
          if (0 <= a && a < n && 0 <= b && b < m) {
            v = getpt(a, b);
            if ((i + j) % 2 == 0)
              addedge(u, v, 1, !(g[i][j] == g[a][b]));
            else
              addedge(v, u, 1, !(g[i][j] == g[a][b]));
          }
        }
      }
    }
    printf("%d\n", MinCostFlow(S, T, T + 1));
  }
  return 0;
}
