1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;


public class pak {

	
	
	private static InputStream in;


	public static void main(String[] args) throws IOException {
		
		in = new BufferedInputStream(System.in);
		
		int n = nextInt();
		int m = nextInt();
	
		int a; // masa przedmiotu
		int c; // udzwig plecaka
		
		long sumA = 0;
		long sumC = 0;
		
		int maxA = Integer.MIN_VALUE;
		int maxC = Integer.MIN_VALUE;
		
		for (int i = 0; i < n; i++) {
			a = nextInt();
			sumA += a;
			if (a > maxA) {
				maxA = a;
			}
		}
		
		for (int i = 0; i < m; i++) {
			c = nextInt();
			sumC += c;
			if (c > maxC) {
				maxC = c;
			}
		}
		
		if (sumA > sumC) {
			fail();
			return;
		}
		
		if (maxA > maxC) {
			fail();
			return;
		}
		
		System.out.println(Math.round(Math.ceil(m / 2.0)));
	}	
	
	
	
	
	
	private static void fail() {
		System.out.println("NIE");
		return;
	}
	
	private static int nextInt() throws IOException {
	    int ret = 0;
	    boolean dig = false;

	    for (int c = 0; (c = in.read()) != -1; ) {
	        if (c >= 48 && c <= 57) {
	            dig = true;
	            ret = ret * 10 + c - 48;
	        } else if (dig) break;
	    }

	    return ret;
	}
	
}