import java.util.*; public class Main { static final int MOD = 1000000007; public static void main(String[] args) { Scanner sc = new Scanner(System.in); int h = sc.nextInt(); int w = sc.nextInt(); int[][] field = new int[h][w]; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { field[i][j] = sc.nextInt(); } } int[] rows = new int[h]; PriorityQueue queue = new PriorityQueue<>(); PriorityQueue next = new PriorityQueue<>(); for (int i = 0; i < h; i++) { rows[i] = sc.nextInt(); long value = rows[i]; for (int j = 0; j < w; j++) { value -= field[i][j]; } queue.add(new Type(true, i, value)); } int[] cals = new int[w]; for (int i = 0; i < w; i++) { cals[i] = sc.nextInt(); long value = cals[i]; for (int j = 0; j < h; j++) { value -= field[j][i]; } queue.add(new Type(false, i, value)); } long total = 0; long max = 0; while (queue.size() > 0) { Type target = queue.poll(); total += target.value; max = Math.max(max, total); while (queue.size() > 0) { Type tmp = queue.poll(); if (target.isRow != tmp.isRow) { if (target.isRow) { tmp.value += field[target.idx][tmp.idx]; } else { tmp.value += field[tmp.idx][target.idx]; } } next.add(tmp); } PriorityQueue t = next; next = queue; queue = t; } System.out.println(max); } static class Type implements Comparable { boolean isRow; int idx; long value; public Type(boolean isRow, int idx, long value) { this.isRow = isRow; this.idx = idx; this.value = value; } public int compareTo(Type another) { if (value < another.value) { return 1; } else if (value == another.value) { return 0; } else { return -1; } } public String toString() { return isRow + ":" + idx + ":" + value; } } }