import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
  auto wh = readln.chomp.split.to!(int[]);

  alias Path = Tuple!(int, int);
  Path[] ps;
  auto pq = BinaryHeap!(Path[], "a[0] > b[0]")(ps);

  auto w = wh[0] + 1;
  auto h = wh[1] + 1;
  auto ns = new Path[][](w * h);
  auto f = new bool[](w * h);
  foreach (i; 0..wh[0]) {
    auto p = readln.chomp.to!int;
    foreach (j; 0..h) {
      ns[i+w*j] ~= Path(p, i+1+w*j);
      ns[i+1+w*j] ~= Path(p, i+w*j);
    }
  }

  foreach (i; 0..wh[1]) {
    auto q = readln.chomp.to!int;
    foreach (j; 0..w) {
      ns[i*w+j] ~= Path(q, (i+1)*w+j);
      ns[(i+1)*w+j] ~= Path(q, i*w+j);
    }
  }

  foreach (e; ns[0]) {
    pq.insert(e);
  }
  f[0] = true;

  int cost;
  while (!pq.empty) {
    auto a  = pq.front;
    pq.popFront;
    if (f[a[1]]) {
      continue;
    }
    //a[1].writeln;
    f[a[1]] = true;
    cost += a[0];
    foreach (e; ns[a[1]]) {
      pq.insert(e);
    }
  }

  cost.writeln;
}
