#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        NSData *stdinData = [[NSFileHandle fileHandleWithStandardInput] availableData];
        NSString *stdinString = [[NSString alloc] initWithData:stdinData encoding:NSUTF8StringEncoding];
        NSArray *stdinArray = [stdinString componentsSeparatedByString:@" "];
        NSInteger w = [[stdinArray objectAtIndex:0] intValue];
        NSInteger h = [[stdinArray objectAtIndex:1] intValue];
        NSMutableArray *pq = [NSMutableArray array];
        
        for (int i=0;i<w+h;i++){
            NSData *stdinData = [[NSFileHandle fileHandleWithStandardInput] availableData];
            NSString *stdinString = [[NSString alloc] initWithData:stdinData encoding:NSUTF8StringEncoding];
            NSNumber *pos = [NSNumber numberWithInt:[stdinString intValue]];
            NSNumber *dir = [NSNumber alloc];
            if (i<w) {
                dir = [NSNumber numberWithInt:0];
            }
            else{
                dir = [NSNumber numberWithInt:1];
            }
            [pq addObject:@[pos,dir]];
        }
        
        [pq sortUsingComparator:^NSComparisonResult(id obj1, id obj2) {
            return [obj1[0] compare:obj2[0]];
        }];
        w++;h++;
        
        NSInteger ans = 0;
        for (id obj in pq) {
            NSInteger isq = [(NSNumber*)obj[1] intValue];
            NSInteger dist = [(NSNumber*)obj[0] intValue];
            if (isq) {
                ans += dist * w;
                h--;
            }
            else {
                ans += dist * h;
                w--;
            }
        }
        
        NSFileHandle *fileHandle = [NSFileHandle fileHandleWithStandardOutput];
        [fileHandle writeData:[[NSString stringWithFormat:@"%ld",ans] dataUsingEncoding:NSUTF8StringEncoding]];
        [fileHandle writeData:[@"\n" dataUsingEncoding:NSUTF8StringEncoding]];
        [fileHandle closeFile];
    }
    return 0;
}
