import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Solution to Rhythm Flow
 * 
 * @author vanb
 */
public class rhythm2_vanb
{
    /** Input. */
    private static Scanner sc;
    
    /** Output. */
    private static PrintStream ps;
    
    private int n;
    private int m;
    private int best[][];
    private int expected[];
    private int actual[];
    
    private int score[] = new int[103];
    
    private int score( int i, int j )
    {
        int diff = Math.abs( expected[i]-actual[j] );
        return diff>102 ? 0 : score[diff];
    }
    
    /**
     * Do it!
     */
    private void doit()
    {
        for( int i=0; i<=15; i++ ) score[i] = 7;
        for( int i=16; i<=23; i++ ) score[i] = 6;
        for( int i=24; i<=43; i++ ) score[i] = 4;
        for( int i=44; i<=102; i++ ) score[i] = 2;
        
        n = sc.nextInt();
        m = sc.nextInt();
        best = new int[n][m];
        expected = new int[n];
        actual = new int[m];
        for( int i=0; i<n; i++ ) expected[i] = sc.nextInt();
        for( int i=0; i<m; i++ ) actual[i] = sc.nextInt();
        
        int max = 0;
        
        for( int i=0; i<n; i++ )
        {
            best[i][0] = score( i, 0 );
            if( best[i][0]>max ) max = best[i][0]; 
        }
        for( int j=1; j<m; j++ ) 
        {
            for( int i=0; i<n; i++ ) 
            {
                int sfori = score( i, j );
                int bestfori = i==0?0:best[i-1][j];
                if( sfori>0 ) for( int k=0; k<j; k++ ) 
                {
                    int s = sfori + (i==0?0:best[i-1][k]);
                    if( s>bestfori ) bestfori = s;
                }
                best[i][j] = bestfori;
                if( bestfori>max ) 
                {
                    max = bestfori;
                }
            }
        }
        
        ps.println( max );
    }
        
    /**
     * Main.
     * 
     * @param args unused
     * @throws Exception
     */
    public static void main( String[] args ) throws Exception
    {
        sc = new Scanner( System.in );
        ps = System.out;
        
        new rhythm2_vanb().doit();
    }

}
