using static System.Math;
using System.Collections.Generic;
using System;

public class PriorityQueue<T> where T : IComparable
{
	private IComparer<T> _comparer = null;
	private int _type = 0;
	private T[] _heap;
	private int _sz = 0;
	private int _count = 0;
	public PriorityQueue(int maxSize, IComparer<T> comparer)
	{
		_heap = new T[maxSize];
		_comparer = comparer;
	}
	public PriorityQueue(int maxSize, int type = 0)
	{
		_heap = new T[maxSize];
		_type = type;
	}
	private int Compare(T x, T y)
	{
		if (_comparer != null) return _comparer.Compare(x, y);
		return _type == 0 ? x.CompareTo(y) : y.CompareTo(x);
	}
	public void Push(T x)
	{
		_count++;
		var i = _sz++;
		while (i > 0)
		{
			var p = (i - 1) / 2;
			if (Compare(_heap[p], x) <= 0) break;
			_heap[i] = _heap[p];
			i = p;
		}
		_heap[i] = x;
	}
	public T Pop()
	{
		_count--;
		T ret = _heap[0];
		T x = _heap[--_sz];
		int i = 0;
		while (i * 2 + 1 < _sz)
		{
			int a = i * 2 + 1;
			int b = i * 2 + 2;
			if (b < _sz && Compare(_heap[b], _heap[a]) < 0) a = b;
			if (Compare(_heap[a], x) >= 0) break;
			_heap[i] = _heap[a];
			i = a;
		}
		_heap[i] = x;
		return ret;
	}
	public int Count() => _count;
	public T Peek() => _heap[0];
	public bool Contains(T x)
	{
		for (int i = 0; i < _sz; i++) if (x.Equals(_heap[i])) return true;
		return false;
	}
	public void Clear()
	{
		while (this.Count() > 0) this.Pop();
	}
	public IEnumerator<T> GetEnumerator()
	{
		var ret = new List<T>();
		while (this.Count() > 0)
		{
			ret.Add(this.Pop());
		}
		foreach (var r in ret)
		{
			this.Push(r);
			yield return r;
		}
	}
	public T[] ToArray()
	{
		T[] array = new T[_sz];
		int i = 0;
		foreach (var r in this)
		{
			array[i++] = r;
		}
		return array;
	}
}

public class Edge
{
	public int to1 { get; set; }
	public int to2 { get; set; }
	public int d { get; set; }
}
public class Node : IComparable
{
	public int id1 { get; set; }
	public int id2 { get; set; }
	public int d { get; set; }
	public int CompareTo(object obj)
	{
		var x = (Node)obj;
		if (this.d > x.d) return 1;
		else if (this.d == x.d) return 0;
		else return -1;
	}
}

public class P
{
	public int from { get; set; }
	public int to { get; set; }
}

public class hello
{
	public static bool first = true;
	public static int BIG = 999999;

	public static void Main()
	{
		while (true)
		{
			var n = int.Parse(Console.ReadLine().Trim());
			if (n == 0) break;
			string[] line = Console.ReadLine().Trim().Split(' ');
			var a = Array.ConvertAll(line, int.Parse);
			line = Console.ReadLine().Trim().Split(' ');
			var b = Array.ConvertAll(line, int.Parse);
			var Ladder0 = getdata(a, n, 1);
			var Ladder1 = getdata(b, n, 1);
			var sLip0 = getdata(a, n, 2);
			var sLip1 = getdata(b, n, 2);
			var aa = new List<Edge>[2, n + 1];
			var mind0 = new int[2, n+1];
			var mind1 = new int[2, n+ 1];
			for (int i = 0; i < 2; i++)
				for (int j = 0; j < n + 1; j++)
				{
					aa[i, j] = new List<Edge>();
					mind0[i, j] = BIG;
					mind1[i, j] = BIG;
				}
			setEdge0(aa, a, n, 0, 1);
			setEdge0(aa, b, n, 1, 0);
			setEdge1(aa, a, n, 0, 1, Ladder0);
			setEdge1(aa, b, n, 1, 0, Ladder1);
			setEdge2(aa, a, n, 0, 1, sLip0);
			setEdge2(aa, b, n, 1, 0, sLip1);
			goDijk(aa, 0, 0, mind0);
			goDijk(aa, 1, 0, mind0);
			if (mind0[0, n] == BIG && mind0[1, n] == BIG
				&& mind1[0, n] == BIG && mind1[1, n] == BIG) Console.WriteLine("NA");
			else
			{
				var t0 = Min(mind0[0, n], mind0[1, n]);
				var t1 = Min(mind1[0, n], mind1[1, n]);
				Console.WriteLine(Min(t0, t1));
			}
		}
	}
	static void setEdge2(List<Edge>[,] aa, int[] a, int n, int me, int front, List<P> sLip)
	{
		foreach (var x in sLip)
		{
			for (int i = x.from; i <= x.to; i++)
				aa[me, i].Add(new Edge { to1 = me, to2 = x.from - 1, d = 0 });
			for (int i = 0; i < 3; i++)
			{
				var ni = x.from - 1 + i;
				if (ni < n) aa[me, x.from - 1].Add(new Edge { to1 = front, to2 = ni, d = 1 });
			}
		}
	}
	static void setEdge1(List<Edge>[,] aa, int[] a, int n, int me, int front, List<P> Ladder)
	{
		foreach (var x in Ladder)
		{
			for (int i = x.from; i <= x.to; i++)
				aa[me, i].Add(new Edge { to1 = me, to2 = x.to, d = 0 });
			for (int i = 0; i < 3; i++)
			{
				var ni = x.to + i;
				if (ni < n) aa[me, x.to].Add(new Edge { to1 = front, to2 = ni, d = 1 });
			}
		}
	}
	static void setEdge0(List<Edge>[,] aa, int[] a, int n, int me, int front)
	{
		for (int i = 0; i < n; i++)
		{
			if (a[i] == 0)
				for (int j = 0; j < 3; j++)
				{
					var ni = i + j;
					if (ni < n) aa[me, i].Add(new Edge { to1 = front, to2 = ni, d = 1 });
				}
		}
		if (a[n - 1] == 0 | a[n - 1] == 1)
			aa[me, n - 1].Add(new Edge { to1 = me, to2 = n, d = 0 });
	}
	static List<P> getdata(int[] a, int n, int t)
	{
		var ans = new List<P>();
		var start = false;
		var from = 0;
		for (int i = 0; i < n; i++)
		{
			if (!start && a[i] == t) { from = i; start = true; }
			else if (start && a[i] != t)
			{
				ans.Add(new P { from = from, to = i - 1 });
				start = false;
			}
		}
		if (start) ans.Add(new P { from = from, to = n - 1 });
		return ans;
	}
	public static void goDijk(List<Edge>[,] aa, int r1, int r2, int[,] mind)
	{
		var pq = new PriorityQueue<Node>(10000, 0);
		pq.Push(new Node { id1 = r1, id2 = r2, d = 0 });
		while (pq.Count() > 0)
		{
			var targ = pq.Pop();
			var nowd = targ.d;
			var nowid1 = targ.id1;
			var nowid2 = targ.id2;
			if (mind[nowid1, nowid2] < nowd) continue;
			mind[nowid1, nowid2] = nowd;
			foreach (var x in aa[nowid1, nowid2])
				if (nowd + x.d < mind[x.to1, x.to2])
				{
					mind[x.to1, x.to2] = nowd + x.d;
					pq.Push(new Node { id1 = x.to1, id2 = x.to2, d = nowd + x.d });
				}

		}
	}
}



Measured memory_bytes: 22028