#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <string>

using namespace std;

const int maxn = (int) 1e3 + 100;

int n, m;
int num1, num2;
char c[maxn][maxn];

int go_up(int summ, int nn, int nm, int a, int b) {
	int res = 0;
	int ost = summ - a * b;

	if (ost == 0) {
		if (a > n || b > m) {
			return 0;
		}
		else if (a > n && b >= m) {
			return 0;
		}
	}

	for (int i = 0; i < nn; i++) {
		for (int j = 0; j < nm; j++) {
			if (i < a && j < b) {
				c[i][j] = '1';
			}
			else if (ost != 0 && i < a && j == b) {
				ost--;
				c[i][j] = '1';
			}
			else {
				c[i][j] = '2';
			}
		}
	}

	for (int i = 0; i < nn; i++) {
		for (int j = 0; j < nm; j++) {
			if (c[i][j] == '2') {
				if (c[i][j + 1] == '2' && c[i + 1][j] == '2' && c[i + 1][j + 1] == '2') {
					res++;
				}
			}
			else if (c[i][j] == '1') {
				if (c[i][j + 1] == '1' && c[i + 1][j] == '1' && c[i + 1][j + 1] == '1') {
					res++;
				}
			}
		}
	}

	return res;
}

int go_down(int summ, int nn, int nm, int a, int b) { // ost down
	int ost = summ - a * b;

	if (ost == 0) {
		if (a > n || b > m) {
			return 0;
		}
	}
	else {
		if (a >= n && b > m) {
			return 0;
		}
	}

	int res = 0;

	for (int i = 0; i < nn; i++) {
		for (int j = 0; j < nm; j++) {
			if (i < a && j < b) {
				c[i][j] = '1';
			}
			else if (ost != 0 && i == a && j < b) {
				ost--;
				c[i][j] = '1';
			}
			else {
				c[i][j] = '2';
			}
		}
	}

	for (int i = 0; i < nn; i++) {
		for (int j = 0; j < nm; j++) {
			if (c[i][j] == '2') {
				if (c[i][j + 1] == '2' && c[i + 1][j] == '2' && c[i + 1][j + 1] == '2') {
					res++;
				}
			} else if (c[i][j] == '1') {
				if (c[i][j + 1] == '1' && c[i + 1][j] == '1' && c[i + 1][j + 1] == '1') {
					res++;
				}
			}
		}
	}

	return res;
}

int main() {
	freopen("video.in", "r", stdin);
	freopen("video.out", "w", stdout);
	
	scanf("%d %d", &n, &m);

	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;

		for (int j = 0; j < m; j++) {
			if (s[j] == '1') {
				num1++;
			} else {
				num2++;
			}
		}
	}

	if (num1 < num2) {
		swap(num1, num2);
	}

	if (num2 == 0) {
		cout << (n - 1) * (m - 1) << endl;
		return 0;
	}

	int result = 1;

	for (int i = 1; i <= max(n, m); i++) {
		int a = i;
		int b = num1 / a;

		result = max(result, go_down(num1, n, m, a, b));
		result = max(result, go_down(num1, n, m, b, a));
		result = max(result, go_up(num1, n, m, a, b));
		result = max(result, go_up(num1, n, m, b, a));
	}

	cout << result << endl;

	return 0;
}