using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static int[] NList => ReadLine().Split().Select(int.Parse).ToArray(); static void Main() { var c = NList; var (h, w) = (c[0], c[1]); var res = new int[h][]; var count = 0; for (var i = 0; i < h; ++i) { res[i] = Enumerable.Repeat(1, w).ToArray(); } if (h % 2 == 0 && w % 2 == 0) { count = h * w; } else if (h % 2 == 0) { for (var i = 0; i < h; ++i) res[i][w - 1] = 0; count = h * (w - 1); } else if (w % 2 == 0) { for (var j = 0; j < w; ++j) res[h - 1][j] = 0; count = (h - 1) * w; } else if (h <= w) { for (var i = 0; i < h; ++i) res[i][i] = 0; for (var i = h; i < w; ++i) res[h - 1][i] = 0; count = h * (w - 1); } else { for (var i = 0; i < w; ++i) res[i][i] = 0; for (var i = w; i < h; ++i) res[i][w - 1] = 0; count = (h - 1) * w; } WriteLine(count); WriteLine(string.Join("\n", res.Select(r => string.Join(" ", r)))); } }