using System; using static System.Console; using System.Linq; using System.Collections.Generic; using System.Security.Cryptography; class Program { static int NN => int.Parse(ReadLine()); static int[] NList => ReadLine().Split().Select(int.Parse).ToArray(); static int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray(); public static void Main() { Solve(); } static void Solve() { var c = NList; var (n, m) = (c[0], c[1]); var a = NList; var s = NList; var set = new HashSet(s); var add = new HashSet(); for (var i = 0; i < s.Length; ++i) for (var j = i; j < s.Length; ++j) if (!set.Contains(a[s[i] + s[j]])) { set.Add(a[s[i] + s[j]]); add.Add(a[s[i] + s[j]]); } while (add.Count > 0) { var nadd = new HashSet(); foreach (var ai in add) for (var i = 0; i < s.Length; ++i) if (!set.Contains(a[ai + s[i]])) { set.Add(a[ai + s[i]]); nadd.Add(a[ai + s[i]]); } add = nadd; } WriteLine(set.Count); } }