#include <fstream>
#include <iostream>
#include <vector>
#include <bitset>
#include <string.h>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <time.h>
#include <stdlib.h>
#include <set>
#include <map>
#include <string>
#include <queue>
#include <deque>

using namespace std;

const char infile[] = "input.in";
const char outfile[] = "output.out";

ifstream fin(infile);
ofstream fout(outfile);

const int MAXN = 1005;
const int oo = 0x3f3f3f3f;

typedef vector<int> Graph[MAXN];
typedef vector<int> :: iterator It;

const inline int min(const int &a, const int &b) { if( a > b ) return b;   return a; }
const inline int max(const int &a, const int &b) { if( a < b ) return b;   return a; }
const inline void Get_min(int &a, const int b)    { if( a > b ) a = b; }
const inline void Get_max(int &a, const int b)    { if( a < b ) a = b; }

int N, M, vertices, match[MAXN], mate[MAXN * MAXN], a[MAXN], b[MAXN];
map<int, int> vertex, inv;
bitset <MAXN> Used;
Graph G;

inline bool pairUp(int Node) {
    if(Used[Node])
        return 0;
    Used[Node] = 1;
    for(It it = G[Node].begin(), fin = G[Node].end(); it != fin ; ++ it)
        if(!mate[*it] || pairUp(mate[*it])) {
            mate[*it] = Node;
            match[Node] = *it;
            return 1;
        }
    return 0;
}

int main() {
    cin.sync_with_stdio(false);
    #ifndef ONLINE_JUDGE
    freopen(infile, "r", stdin);
    freopen(outfile, "w", stdout);
    #endif
    cin >> N >> M;
    for(int i = 1 ; i <= N ; ++ i)
        cin >> a[i];
    for(int i = 1 ; i <= M ; ++ i)
        cin >> b[i];
    for(int i = 1 ; i <= N ; ++ i)
        for(int j = 0 ; j <= M ; ++ j) {
            int newval = a[i] - b[j];
            if(!vertex[newval]) {
                vertex[newval] = ++ vertices;
                inv[vertices] = newval;
            }
            G[i].push_back(vertex[newval]);
        }
    int matches = 0;
    for(bool change = true ; change ; ) {
        change = false;
        Used.reset();
        for(int i = 1 ; i <= N; ++ i)
            if(!match[i])
                if(pairUp(i)) {
                    ++ matches;
                    change = true;
                }
    }
    cout << matches << '\n';
    for(int i = 1 ; i <= N ; ++ i)
        if(match[i])
            cout << inv[match[i]] << ' ';
        else cout << a[i] << ' ';
    fin.close();
    fout.close();
    return 0;
}