print((function(f, s1, s2) return f(s1, s2) end)(function (s1, s2) local k, n = s1:match("(%d+)%s(%d+)") local r = tonumber(k) * tonumber(n) s2:gsub("%d+", function (e) r = r - tonumber(e) end) return r < 0 and -1 or r end, io.stdin:read("*l"), io.stdin:read("*l")))