#include<bits/stdc++.h>
#include<unordered_map>
#include<vector>
using namespace std;
int main()
{
    int c;
    cin>>c;
    vector<int>a,b;
    unordered_map<int,int>p;
    unordered_map<int,int>q;
        for(int i=0;i<c;i++)
    {int x; cin>>x;
        a.push_back(x);
      if(p.count(a[i])>0)  {p[a[i]]++;
      }
      else   {p[a[i]]=1;
      }
    }
   for(int i=0;i<c;i++)
   {int x; cin>>x;
   b.push_back(x);
    if(q.count(b[i])>0)  {q[b[i]]++;
      }
      else   {q[b[i]]=1;
      }
      }
   int sum=0;
   int i;
   for( i=1;i<=5;i++)
   {if(abs(p[i]-q[i])%2==0)
   {
       sum+=abs(p[i]-q[i])/2;
   }
   else break;
   }
  if(sum%2==0&&i==6) cout<<sum/2;
   else cout<<-1;
}

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
using namespace std;

#define pb         push_back
#define mp         make_pair
#define ll         long long
#define PI         acos(-1.0)
#define ALL(A)     ((A).begin(), (A).end())
#define vsort(v)   sort(v.begin(),v.end())
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)

int main(){
    int n;
    cin >> n;
    int A[5] = {0}, B[5] = {0};
    int input;
    FOR(i, 0, n){
        cin >> input;
        A[input-1]++;
    }
    FOR(i, 0, n){
        cin >> input;
        B[input-1]++;
    }

    //すでに同じなら消す
    FOR(i, 0, 5){
        if(A[i]>=B[i]){
            A[i] -= B[i];
            B[i] = 0;
        }
        else{
            B[i] -= A[i];
            A[i] = 0;
        }
}

    FOR(i, 0, 5){
        if(A[i]%2==1 || B[i]%2==1){
            cout << "-1" << endl;
            return 0;
        }
    }

    int ans = 0;
    //交換できるか
    FOR(ai, 0, 5){
        FOR(bi, 0, 5){
            if(ai==bi) continue;
            if(A[ai]>B[bi]){
                ans += B[bi] / 2;
                A[ai] -= B[bi];
                B[bi] = 0;
            }
            else{
                ans += A[ai] / 2;
                B[bi] -= A[ai];
                A[ai] = 0;
            }
        }
    }

    FOR(i, 0, 5){
        if(A[i]!=0 || B[i]!=0){
            cout << "-1" << endl;
            return 0;
        }
    }
    cout << ans << endl;
}

///
#include <bits/stdc++.h>
#define pb push_back
typedef long long ll;
using namespace std;
const int maxn=100002;
const ll MOD=1000000007;

int n,a[102],b[102],cntA[6],cntB[6],cnt[6],take,give;
int main()
{
//    freopen("nhap.inp", "r", stdin);
    cin>>n;
    for (int i=1; i<=n; i++)
    {
        cin>>a[i];
        cntA[a[i]]++;
        cnt[a[i]]++;
    }
    for (int i=1; i<=n; i++)
    {
        cin>>b[i];
        cntB[b[i]]++;
        cnt[b[i]]++;
    }
    for (int i=1; i<=5; i++)
        if (cnt[i] %2 != 0)
        {
            cout<<-1;
            return 0;
        }
    for (int i=1; i<=5; i++)
    {
        if (cntA[i] < cnt[i]/2)
            take += cnt[i]/2 - cntA[i];
        if (cntA[i] > cnt[i]/2)
            give += cntA[i] - cnt[i]/2;
    }
    cout<<max(take,give);
    return 0;
}

#include<bits/stdc++.h>
using  namespace  std;
int n,cjc[6],ans,cj,f;
int main()
{
	cin>>n;
	for(int a=0;a<n;a++)
	{
		cin>>cj;
		cjc[cj]++;
	}
	for(int a=0;a<n;a++)
	{
		cin>>cj;
		cjc[cj]--;
	}
	for(int a=1;a<=5;a++)
	{
		if(cjc[a]!=0)f++;
	}
	for(int a=1;a<=5;a++)
	{
		cjc[a]=abs(cjc[a]);
		if(cjc[a]%2!=0)
		{
			ans=-1;
			break;
		}
		else
		{
			ans+=cjc[a]/2;
		}
	}
	if(f>1&&ans!=-1)ans=ans/2;
	cout<<ans<<endl;
	return 0;
}

#include <bits/stdc++.h>
#define ll long long int
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define itr vector <int> :: iterator
#define vi vector <int>
#define lb lower_bound
#define fast ios::sync_with_stdio(0);cin.tie(0);
#define tt int t; cin>>t; while(t--)
#define ff first
#define ss second
#define fora(i,a,b) for(i=a;i<b;i++)
#define reva(i,a,b) for(i=a;i>=b;i--)
using namespace std;

bool prime[100010];

void SieveOfEratosthenes(int n){
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*2; i<=n; i += p)
                prime[i] = false;
        }
    }
}

ll power(ll x, ll y, ll p)
{
    int res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;

        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}

int main()
{
    fast
    ll i,j,k,n,m;
    cin>>n;
    int arr[6]={0},a[6]={0};
    fora(i,0,n){
        cin>>m;
        arr[m]++;
    }

    fora(i,0,n){
        cin>>m;
        a[m]++;
    }
    int a1=0;
    fora(i,1,6){
        int mi=arr[i]+a[i];
        if(mi%2==1){
            cout<<"-1\n";
            return 0;
        }
        mi/=2;
        a1+=abs(mi-arr[i]);
    }
    cout<<a1/2<<endl;

}

#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int n = 0, m = 0;
    cin >> n;
    vector<int> buf1(6, 0);
    vector<int> buf2(6, 0);
    for (int i = 0; i < n; i++)
    {
        cin >> m;
        buf1[m]++;
    }
    for (int i = 0; i < n; i++)
    {
        cin >> m;
        buf2[m]++;
    }
    m = 0;
    for (int i = 1; i < 6; i++)
    {
        if (buf1[i] != buf2[i])
        {
            if (buf1[i] < buf2[i])
            {
                swap(buf1[i], buf2[i]);
            }
            if ((buf1[i] - buf2[i]) % 2 == 0)
            {
                m += (buf1[i] - buf2[i]) / 2;
            }
            else
            {
                cout << -1;
                return 0;
            }
        }
    }
    cout << m / 2;
}

#include<bits/stdc++.h>
using namespace std;
int a,n,sum=0;
int main()
{
    map<int ,int > mp1,mp2;
    cin>>n;
    for(int i=0;i<n;i++)
    {
      cin>>a;
      mp1[a]++;
    }
    for(int i=0;i<n;i++)
    {
      cin>>a;
      mp2[a]++;
    }
    for(int i=1;i<=5;i++)
    {
    	if(abs(mp1[i]-mp2[i])%2!=0)
    	{
    		cout<<-1;
    		return 0;
    	}
    	else
        sum+=abs(mp1[i]-mp2[i]);
    }
    if(sum%4==0)
    {
        cout<<sum/4;
    }
    else
    cout<<-1;
}

/*BISMILLAHIR RAHMANIR RAHIM*/
#include<bits/stdc++.h>
#include<string>
#define case(res) printf("Case %d: %d\n", k, res)
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define PI acos(-1)
#define lli long long int
#define loop(a, n, x) for(int i=a; i<=n; i+=x)
#define npoint(x) fixed << setprecision(x)
#define ALL(x) x.begin(), x.end()
#define rev(x) reverse(x.begin(), x.end())
/*-----------------ANUPAM AKIB-------------------*/

using namespace std;

int gpa1[8], gpa2[8];
int main(){
    int n, sum=0, k;
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> k;
        gpa1[k]++;
    }
    for(int i=0; i<n; i++){
        cin >> k;
        gpa2[k]++;
    }
    bool flag=true;
    for(int i=1; i<=5; i++){
        if((gpa1[i]+gpa2[i])%2==0){
            sum+=abs(gpa1[i]-gpa2[i])/2;
        }
        else{
            flag=false; break;
        }
    }
    flag==true? cout << sum/2 : cout << -1;
    return 0;
}

#include <bits/stdc++.h>

using namespace std;
int n,a[6],b[6],s;
int main()
{
    cin>>n;
    for(int i=1;i<=n;++i)
    {int u;
        cin>>u;
        a[u]++;
    }
      for(int i=1;i<=n;++i)
    {int u;
        cin>>u;
        b[u]++;

    }
for(int i=1;i<=5;++i)
 {
     if(abs(b[i]+a[i])%2==1) {cout<<-1;return 0;}
     s+=(a[i]+b[i])/2-min(a[i],b[i]);
 }
 cout<<s/2;
    return 0;
}

#include <bits/stdc++.h>
#define ll long long int
#define Max 1000007
#define fast ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;

ll n;
ll a[10], b[10];

int main() {
    fast
    cin >> n;

    ll tmp;
    for(ll i = 0 ; i < n ; i++) {
        cin >> tmp;
        a[tmp]++;
    }
    for(ll i = 0 ; i < n ; i++) {
        cin >> tmp;
        b[tmp]++;
    }
    bool f = false;
    for(ll i = 1 ; i <= 5 ; i++) {
        tmp = min(a[i],b[i]);
        if(tmp) {
            a[i] -= tmp;
            b[i] -= tmp;
            f = true;
        }
    }

    ll ans = 0;

    for(ll i = 1 ; i <= 5 ; i++) {
        if(a[i]) {
            for(ll j = 1 ; j <= 5 ; j++) {
                ll x = min(b[j],a[i]);
                if(x%2 == 0) {
                    ans += x/2;
                    a[i] -= x;
                    b[j] -= x;
                    f = true;
                }
            }
        }
    }

    for(ll i = 1 ; i <= 5 ; i++){
        if(a[i] || b[i]){
            f = false;
            break;
        }
    }

    if(!f) {
        cout << -1;
        return 0;
    }

    cout << ans;

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
constexpr int maxl = 6;
int numa[maxl], numb[maxl];
int main()
{
	int n;
	cin >> n;
	for(int i = 0;i < n; i++)
	{
		int a;
		cin >> a;
		numa[a]++;
	}
	for(int i = 0; i < n; i++)
	{
		int b;
		cin >> b;
		numb[b]++;
	}
	int sum = 0;
	int flag = 0;
	for(int i = 1; i <= 5; i++)
	{
		sum += abs(numa[i] - numb[i]);
		if(abs(numa[i] - numb[i]) % 2 == 1) flag = 1;
	}
	if(sum % 4 != 0 || flag)
		cout << -1 << endl;
	else
		cout << sum / 4 << endl;
	return 0;
}

//    Author: Niraj vadhaiya
        #include<bits/stdc++.h>
        using namespace std;
        #define mod 1000000007
        #define pb push_back
        #define ll long long
        #define mp make_pair
        #define f first
        #define s second

        int main()
        {

            int n;
            //int p[n],q[n];
            cin>>n;
            int a[6],b[6];
            memset(a,0,sizeof(a));
            memset(b,0,sizeof(b));
            for(int i=0;i<n;i++)
            {
                int x;
                cin>>x;
                a[x]++;
            }
            for(int i=0;i<n;i++)
            {
                int y;
                cin>>y;
                b[y]++;
            }
            ll sum=0;
            for(int i=1;i<6;i++)
            {

                if((a[i]+b[i])%2!=0)
                {
                    cout<<"-1";
                    return 0;
                }
                else
                {
                    sum+=abs(a[i]-b[i]);
                }
            }
            cout<<sum/4;
            return 0;
        }

#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#include<bits/stdc++.h>
#define F first
#define S second
#define vec vector
#define ms multiset
#define pb push_back
#define pll pair<ll,ll>
#define pdd pair<ld, ld>
#define pq priority_queue
#define umap unordered_map
#define uset unordered_set
#define pii pair<int, int>
#define pnn pair<Node*, Node*>
#define uid uniform_int_distribution
#define FILE ifstream in("input.txt");ofstream out("output.txt");
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);
using namespace std;
typedef string str;
typedef long long ll;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); //uid<int> u1(5, 10); u1(rnd);

int main() {
    fast;
    int a,x; cin>>a;
    vec<int> d(5);
    for(int q=0; q<a; q++) cin>>x, x--, d[x]++;
    for(int q=0; q<a; q++) cin>>x, x--, d[x]--;
    ll o =0;
    for(int q=0; q<5; q++) if(d[q]%2) o = -2e9; else o+=abs(d[q])/2;
    cout<<(o<0 ? -1 : o/2);
}

#include <iostream>

using namespace std;
int v1[6];
int v2[6];
int main()
{
    int n,a,cnt=0;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a;
        v1[a]++;

    }
    for(int i=1;i<=n;i++)
    {
        cin>>a;
        v2[a]++;
    }
    for(int i=1;i<=5;i++)
    {
        cnt+=max(v1[i],v2[i])-min(v1[i],v2[i]);
    }
    for(int i=1;i<=5;i++)
    {
        if((v1[i]+v2[i])%2==1)
        {
            cout<<"-1";
            return 0;
        }
    }
    cout<<cnt/4;
        return 0;
}

#include <iostream>
#include <cmath>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <math.h>
#include <map>
#include <iomanip>
#include <functional>
#include <list>
#include <random>
#include <deque>
#include <queue>
#include <regex>
#include <bitset>
#include <cstdio>

using namespace std;

typedef long long int64;
typedef unsigned long long uint64;
typedef long double double64;
typedef vector<int64> VI;
typedef pair<int64, int64> PII;

template <typename T> void alert(const T& t) { cout << t; exit(0); }
template<typename T> inline void alert(vector<T> &t, char delim = ' ') { for (T const& ti : t) cout << ti << delim; exit(0); }

#define mp make_pair
#define forn(i, n) for (int64 i = 0; i < int64(n); i++)
#define nfor(i, n) for (int64 i = int64(n) - 1; i >= 0; i--)
#define fore(i, l, r) for (int64 i = int64(l); i < int64(r); i++)
#define efor(i, l, r) for (int64 i = int64(l) - 1; i >= int64(r); i--)
#define all(a) (a).begin(), (a).end()
#define mp(x, y) make_pair((x), (y))
#define sqr(a) ((a) * (a))
#define stodigit(a) (a - '0')
#define chtodigit(a) (a - 'a')

const int64 MAX64 = 1 + 1e+18;
const int  MAX = 1 + 1e+9;
const double PI = 3.1415926536;
const int64 CEL = 26;
int64 MID(int64 l, int64 r) { return (l + r) / 2; }
int64 LSON(int64 u) { return u * 2; }
int64 RSON(int64 u) { return u * 2 + 1; }

/*----------------------------------------------------------*/

typedef vector<int64> Edges_t;

struct Node
{
	Node() : color('w') {}
	char color;
	Edges_t edges;
};

typedef vector<Node>  Graph_t;

Graph_t graph;

int64 answer = 0;

int64 DFS(int64 start, int64 cnt)
{
    forn(i, graph[start].edges.size())
    {
        int64 u = graph[start].edges[i];

        DFS(u, cnt + 1);
    }

    answer = max(answer, cnt);
}

/*----------------------------------------------------------*/

struct Point
{
	Point() : x(0), y(0) {};
	Point(double X, double Y) : x(X), y(Y) {};

	double x;
	double y;
};

int64 GCD(int64 a, int64 b)
{
	if (b == 0) return a;
	else return GCD(b, a % b);
}

int64 LCM(int64 a, int64 b)
{
	return (a * b) / GCD(a, b);
}

// степень двойки if ((i & (i - 1)) == 0)
//ceil(); floor(n + 0.5);

#define TASKNAME "lepus"

int main()
{
#ifdef _DEBUG
	freopen("ReadMe.txt", "r", stdin);
#else
{
	//freopen(TASKNAME".in", "r", stdin);
	//freopen(TASKNAME".out", "w", stdout);
}
#endif

    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    //cout.tie(0);
    int64 n; cin >> n;
    vector<int64> vec1(n), vec2(n);
    map<int64,int64> ma, m1, m2;

    forn(i,n)
    {
        cin >> vec1[i];
        ma[vec1[i]]++;
        m1[vec1[i]]++;
    }

    forn(i,n)
    {
        cin >> vec2[i];
        ma[vec2[i]]++;
    }

    for(auto it : ma) if(it.second % 2 == 1)  alert(-1);
    int64 answer = 0;

    for(int64 i = 1; i < 6; i++)
    {
        if(m1[i] < ma[i] / 2) answer += m1[i] - ma[i] / 2;
    }

    alert(-answer);

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n;
    cin>>n;
    ll a[n],b[n];
    map<ll,ll>a1;
    map<ll,ll>b1;
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        a1[a[i]]++;
    }
    for(ll i=0;i<n;i++)
    {
        cin>>b[i];
        b1[b[i]]++;
    }
    ll count=0;
    for(ll i=1;i<=5;i++)
    {
        if((a1[i]+b1[i])%2==1)
        {
            count=-1;
            break;
        }
        else
        {
           if(a1[i]-b1[i]>0)
           {
               count+=(a1[i]-b1[i])/2;
           }
        }
    }
    cout<<count<<"\n";
    return 0;
}

#include<bits/stdc++.h>
using namespace std;

int main(){
    int n;
    cin >> n;
    int a[n], b[n], cnt[5] = {0, 0, 0, 0, 0};
    for (int i = 0; i < n; i++){
        cin >> a[i];
        cnt[a[i] - 1]++;
    }
    for (int i = 0; i < n; i++){
        cin >> b[i];
        cnt[b[i] - 1]--;
    }
    int sum = 0;
    for (int i = 0; i < 5; i++){
        if (cnt[i] % 2 == 1 || cnt[i] % 2 == -1){
            cout << -1;
            return 0;
        }
        else{
            sum += abs(cnt[i]);
        }
    }
    cout << sum / 4;
}

#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define read(a) scanf("%d", &a)
#define readl(a) scanf("%lld", &a)
#define mem(a) memset(a, 0, sizeof(a));
#define Buff ios::sync_with_stdio(false)
typedef long long ll;
using namespace std;
const int INF = 1e9 + 7;
const int N = 2e5 + 7;
const int M = 1e6 + 7;

int a[6], b[6];
priority_queue<int> q;
signed main()
{
    Buff;
    int n, x;
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        cin >> x;
        a[x]++;
    }
    for(int i = 1; i <= n; i++)
    {
        cin >> x;
        b[x]++;
    }

    int flag = 1;
    int ans = 0;
    for(int i = 1; i <= 5; i++)
    {
        if((a[i] + b[i])%2)
        {
            flag = 0;
            break;
        }
        int x = abs(a[i]-(a[i] + b[i]) / 2);
//        cout << x << endl;
        ans += x;
    }
    cout << (flag ? ans/2:-1) << endl;

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main() {
    long long int c[201021]={0},a,b,n,i,s=0 ;
    cin>>n;
    for(i=0;i<n;i++){cin>>a;c[a]++;}
    for(i=0;i<n;i++){cin>>b;c[b]--;}
    for(i=1;i<=5;i++)
    {
    if(abs(c[i]) & 1){cout<<"-1";return 0;}
    else
    s+=abs(c[i]);
    }
    cout<<s/4<<endl;
    return 0;
    }

#include <bits/stdc++.h>
#define ll long long int
using namespace std;
ll min( ll a,  ll b) { return (a < b) ? a : b;}
ll max(ll a, ll b) {return (a > b) ? a : b;}
double pi = 2*acos(0.0);

int main()
{
    ll te=1;
    //cin>>te;
    while(te--){
      ll n,p,mark=0;
      cin>>n;
      ll hash1[6]={0};
      ll hash2[6]={0};
      for(int i=0;i<n;i++){
       cin>>p;
       hash1[p]++;
      }
      for(int i=0;i<n;i++){
       cin>>p;
       hash2[p]++;
      }
      ll po=1;
      for(int i=1;i<6;i++){
        //  cout<<hash1[i]<<" "<<hash2[i]<<endl;
          if((hash1[i] + hash2[i]) % 2 == 1)
           po=0;

          mark+= abs(hash1[i]-hash2[i]);
      }
      if(mark%4==0 && po==1)
      cout<<mark*0.25;
      else
       cout<<"-1"<<endl;
    }
}

#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
using pll=pair<long long,long long>;
#define ITR(i,c) for(auto i=begin(c);i!=end(c);++i)
#define FORE(x,c) for(auto &x:c)
#define FOR(i,a,n) for(int i=a,i##_len=(int)(n);i<i##_len;++i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i=(int)n;i>=0;--i)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)   // c++14
#define SZ(c) ((int)c.size())
#define EXIST(c,x) (c.find(x)!=end(c))
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,v) os << *i << (i==end(v)-1 ? "" : " "); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,v) is >> * i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
        is >> p.first >> p.second; return is; }
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
//------------------------------------------------------------------------------
struct before_main_function {
    before_main_function() {
    #ifdef int
        #undef INF
        #define INF INFLL
        cerr<<"\x1b[7m"<<"'int' is defined as 'long long' !!!!"<<"\x1b[m"<<endl;
    #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
    }
} before_main_function;
//------------------------------------------------------------------------------

signed main() {
    int n;
    cin>>n;
    vi a(5,0),b(5,0),c(5,0);
    REP(i,n) {
        int t;
        cin>>t;
        t--;
        a[t]++;
    }
    REP(i,n) {
        int t;
        cin>>t;
        t--;
        b[t]++;
    }
    REP(i,5) {
        c[i]=a[i]+b[i];
        if(c[i]%2!=0) {
            cout<<"-1"<<endl;
            return 0;
        }
    }
    int t=0;
    int ans=0;
    REP(i,5) {
        if(c[i]/2!=a[i]) {
            t+=c[i]/2-a[i];
            ans+=c[i]/2-min(a[i],b[i]);
        }
    }
    if(t!=0) {
        cout<<"-1"<<endl;
        return 0;
    }
    cout<<ans/2<<endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
using pll=pair<long long,long long>;
#define ITR(i,c) for(auto i=begin(c);i!=end(c);++i)
#define FORE(x,c) for(auto &x:c)
#define FOR(i,a,n) for(int i=a,i##_len=(int)(n);i<i##_len;++i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i=(int)(n);i>=0;--i)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)   // c++14
#define SZ(c) ((int)c.size())
#define EXIST(c,x) (c.find(x)!=end(c))
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,v) os << *i << (i==end(v)-1 ? "" : " "); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,v) is >> * i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
        is >> p.first >> p.second; return is; }
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
//------------------------------------------------------------------------------
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
            cerr<<"\x1b[7m"<<"'int' is 'long long'"<<"\x1b[m"<<endl;
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
    }
} before_main_function;
//------------------------------------------------------------------------------

signed main() {
    int n;
    cin>>n;
    vi a(5,0),b(5,0),c(5,0);
    REP(i,n) {
        int t;
        cin>>t;
        t--;
        a[t]++;
    }
    REP(i,n) {
        int t;
        cin>>t;
        t--;
        b[t]++;
    }
    REP(i,5) {
        c[i]=a[i]+b[i];
        if(c[i]%2!=0) {
            cout<<"-1"<<endl;
            return 0;
        }
    }
    int t=0;
    int ans=0;
    REP(i,5) {
        if(c[i]/2!=a[i]) {
            t+=c[i]/2-a[i];
            ans+=c[i]/2-min(a[i],b[i]);
        }
    }
    if(t!=0) {
        cout<<"-1"<<endl;
        return 0;
    }
    cout<<ans/2<<endl;
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define re return
#define sz(a) (int)a.size()
#define mk(a, b) make_pair(a, b)
#define fi first
#define se second
#define re return
#define forn(i, n) for (int i = 0; i < int(n); i++)

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef pair<long long, long long> pll;
typedef long double ld;
typedef unsigned long long ull;
const ll mod = int(1e9) + 7;

int dir[8][2]={{1,0},{0,1},{0,-1},{-1,0},{-1,1},{1,-1},{1,1},{-1,-1}};

int t[6];
int t2[6];
int main()
{
   int n;
   cin>>n;

   int a;
   for(int i=0;i<n;i++)
    {
        cin>>a;
        t[a]++;
    }
    for(int i=0;i<n;i++)
    {
        cin>>a;
        t2[a]++;
    }

    int x=0,y=0;
int result=0;
    for(int i=1;i<6;i++)
    {
        if((t[i]+t2[i])%2==1)
        {
            cout<<-1;
            return 0;
        }
        int total=(t[i]+t2[i])/2;
        int tmp=x;
        x+=t[i]-total;
        y+=t2[i]-total;

        if(tmp*x<=0)
            result+=abs(x);

        if(tmp>0 && x>tmp)
            result+=x-tmp;
        if(tmp<0 && tmp>x)
            result+=tmp-x;
    }
    if(x==0 && y==0)
        cout<<result;
    else
    cout<<-1;

}

//Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>

using namespace std;

map<int, int> M;
map<int, int> P;

int main()
{
	int n;
	cin >> n;
	int arr1[n], arr2[n], sum = 0;

	for(int i = 0; i < n; i++){
        cin >> arr1[i];
        M[arr1[i]]++;
	}

	for(int i = 0; i < n; i++){
        cin >> arr2[i];
        P[arr2[i]]++;
	}

	for(int i = 1; i <= 5; i++){
        sum += abs(M[i] - P[i]);
        if((M[i] + P[i]) % 2 != 0){
            cout << -1;
            return 0;
        }
	}
	if(sum % 4 == 0) cout << sum / 4;
	else cout << -1;
}

#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;

int main()
{
	int n;
	cin>>n;
	int a[n],b[n],c[7]={0},d[7]={0};
	for(int i=0;i<n;i++)
	cin>>a[i];
	for(int i=0;i<n;i++)
	cin>>b[i];
	sort(a,a+n);
	sort(b,b+n);
	for(int i=0;i<n;i++)
	{
			c[a[i]]++;
			d[b[i]]++;
	}
	int l=0,k=0;
	for(int i=0;i<7;i++)
	{
		if((c[i]+d[i])%2==1)
		{
			cout<<"-1";
			return 0;;
		}
		if(c[i]>d[i])
		k=k+c[i]-d[i];
		else if(d[i]>c[i])
		l=l+(d[i]-c[i]);
	}
	if(k==l&&k%2==0)
		cout<<k/2;
		else
		cout<<"-1";
}

#include <iostream>;
using namespace std;

int main()
{
	int n;
	cin >> n;
	int mas[6] = { 0 };
	int x;
	for (int i = 0; i < n; i++)
	{

		cin >> x;
		mas[x]++;

	}
	for (int i = 0; i < n; ++i)
	{
		cin >> x;
		mas[x]--;
	}

	for (int i = 0; i <= 5; i++)
		if ((mas[i] % 2 == 1)||(mas[i]%2==-1))
		{
			cout << -1; return 0;
		}
	int sum = 0;
	for (int i = 0; i <= 5; i++)
		if (mas[i] > 0)
			sum += mas[i] / 2;
	cout << sum;

	return 0;
}

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
ll a[5+1],b[5+1];

main()
{

    ll n;

    cin >> n;

    for(ll i = 0;i < n;i++)
    {

        ll temp;

        cin >> temp;
        a[temp]++;

    }
    for(ll i = 0;i < n;i++)
    {

        ll temp;

        cin >> temp;
        b[temp]++;

    }

    bool flag = true;
    ll ans1 = 0,ans = 0;

    for(ll i = 1;i <= 5;i++)
    {

        if((a[i] + b[i])%2)
        {

            flag = false;
            ans = -2;
            break;

        }
        ll k = (a[i] + b[i])/2;
        ans += abs(a[i] - b[i])/2;

    }

    cout << ans/2;

}

#include "bits/stdc++.h"
using namespace std;
int a[6];

int main() {
	int n;
	cin >> n;
	int v;
	for (int i=0; i<n; i++) {
		cin >> v;
		a[v]++;
	}
	for (int i=0; i<n; i++) {
		cin >> v;
		a[v]--;
	}
	int ans = 0;
	for (int i=1; i<6; i++) {
		if (a[i]%2 == 0) {
			ans += ((abs(a[i])/2.0));
		}else {
			printf("-1\n");
			return 0;
		}
	}
	printf("%d\n", (int)ceil(ans/2.0));
}

//XDZ --> by Mr.D ;
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define SET(a , b) memset(a,b,sizeof(a))
#define sz(v1) (int)v1.size()
/*
      █ █  █▀▀▄  ▀▀▀█
       █   █░▒█    █
      █ █  █▄▄▀  ▄█▄▄▄
*/
int n,a,b,c[6],d[6],ans;
int main()
{
    cin>>n;
    for(int i=1; i<=n; i++)
        cin>>a, c[a]++;

    for(int i=1; i<=n; i++)
        cin>>a,d[a]++;

    for(int i=1; i<6; i++)
    {
        if ((c[i]+d[i])%2)
            return cout<<-1,0;

        ans+=abs((c[i]-d[i])/2);
    }
    cout<<ans/2;
}

#include<bits/stdc++.h>
#define pf printf
#define sf scanf
#define ll long long
#define llu unsigned long long
#define M 100000
#define pb push_back
#define ppb pop_back
#define F first
#define S second
#define Check(x,w) (x&(1<<w))==(1<<w)?true:false
#define pii pair<int,int>
#define pvi pair<vector<int>,int>
#define EPS 1e-5
#define PI acos(-1)
#define Mems(p,n) memset(p,n,sizeof(p))
#define MOD 1000000007
#define inf -2000000000;
#define INT(c)  ((int)((c) - '0'))
#define CHAR(i) ((char)(i + int('0')))
using namespace std;

template<class T>
inline bool fs(T &x)
{
    int c=getchar();
    int sgn=1;
    while(~c&&c<'0'||c>'9')
    {
        if(c=='-')sgn=-1;
        c=getchar();
    }
    for(x=0; ~c&&'0'<=c&&c<='9'; c=getchar())
        x=x*10+c-'0';
    x*=sgn;
    return ~c;
}

int ara[2][7],n;

int main()
{
    //freopen("in","r",stdin);
    //freopen("out.txt","w",stdout);
    int a,b,c,d,e,f,g,h,i,j;
    a=b=0;
    fs(n);
    for(i=0; i<n; i++)
    {
        fs(c);
        ara[0][c]++;
    }
    for(i=0; i<n; i++)
    {
        fs(c);
        ara[1][c]++;
    }
    c=0;
    for(i=1; i<=5; i++)
    {
        //pf("i=%d 1=%d 2=%d\n",i,ara[0][i],ara[1][i]);
        if(ara[0][i]>ara[1][i])
            a+=(ara[0][i]-ara[1][i]);
        if(ara[0][i]<ara[1][i])
            b+=(ara[1][i]-ara[0][i]);
        if((ara[0][i]+ara[1][i])%2!=0)
            c=1;
    }
    //cout<<a<<" "<<b<<endl;
    if(a==b && a%2==0 && c==0)
        pf("%d\n",a/2);
    else
        pf("-1\n");
    return 0;
}

#include <bits/stdc++.h>

#define int long long
#define mp make_pair
#define pb push_back
#define min3(a,b,c) min(min(a,b),c)
#define max3(a,b,c) max(max(a,b),c)
#define EPS 0.00000001

const int inf = 4e18; ///
const int mod2 = 1e9+7;

using namespace std;
void print(vector<int> & v){
    for(auto it:v) cout << it << " ";
    cout << "\n";
}

signed main(){
    int n;
    cin >> n;
    int cnt[5];
    int cnt1[5];
    memset(cnt,0,sizeof cnt);
    memset(cnt1,0,sizeof cnt1);
    for(int i =0;i<n;i++){
        int x;
        cin >> x;
        cnt[x-1]++;
    }
    for(int i =0;i<n;i++){
        int x;
        cin >> x;
        cnt1[x-1]++;
    }
    int k = 0;
    for(int i= 0;i<5;i++){
        k += (cnt[i]-cnt1[i]);
        if((cnt[i]+cnt1[i])&1){
            cout << -1;
            return 0;
        }
    }
    if(k){
        cout << 0-1;
        return 0;
    }
    int c = 0;
    for(int i=  0;i<5;i++) c += abs(cnt[i]-cnt1[i]);
    cout << c/4;

}

#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;
int main()
{
	int N,A[105],B[105],Tot[105]={0},Cnt[105]={0};
	cin>>N;
	for(int I=1;I<=N;++I){cin>>A[I];++Tot[A[I]],++Cnt[A[I]];}
	for(int I=1;I<=N;++I){cin>>B[I];++Tot[B[I]];}
	int Ans=0;
	for(int I=1;I<=5;++I){
		if(Tot[I]==0)continue;
		if(Tot[I]&1){
			puts("-1");
			return 0;
		}
		Ans+=abs(Cnt[I]-(Tot[I]>>1));
	}
	cout<<(Ans/2)<<endl;
	return 0;
}

#include<cstdio>
#include<algorithm>
using namespace std;

int main(){
  int n,a[5],b[5],ans = 0;
  scanf("%d",&n);
  for(int i=0;i<5;i++){
    a[i] = 0;
    b[i] = 0;
  }
  for(int i=0;i<n;i++){
    int x;
    scanf("%d",&x);
    a[x-1]++;
  }
  for(int i=0;i<n;i++){
    int x;
    scanf("%d",&x);
    b[x-1]++;
  }
  for(int i=0;i<5;i++){
    if((a[i]+b[i])%2!=0){
      printf("-1\n");
      return 0;
    }else{
      ans += (max(a[i],b[i]) - min(a[i],b[i])) / 2;
    }
  }
  printf("%d\n",ans/2);
  return 0;
}

#include <bits/stdc++.h>
#define LL long long
#define L long
#define I int
#define LD long double
#define m(a,b) memset(a,b,sizeof(a))
#define mp make_pair
#define pb push_back
#define MAX 1000000007
#define INF 1e18+1

#define cint(d) scanf("%d", &d)
#define clong(d) scanf("%lld", &d)

#define FOR(i, s, n) for(I i = s; i < n; i++)
#define FORR(i, n, s) for(I i = n-1; i >= s; i--)
#define v(i) vector<i>
using namespace std;
I ar1[6], ar2[6];
int main()
{
    I temp;
    I n;
    cin>>n;
    FOR(i,0,n){
        cint(temp);
        ar1[temp]++;
    }
    FOR(i,0,n){
        cint(temp);
        ar2[temp]++;
    }
    I ans = 0;
    FOR(i,0,6){
        if((ar1[i]+ar2[i])%2){
            cout<<"-1";
            return 0;
        }
        ans += abs(ar1[i] - ar2[i])/2;
    }
    cout<<ans/2<<endl;
}

#include <iostream>
#include <cstdlib>

using namespace std;

int main()
{
	int n,p,q,count=0,flag=0,ans=0,temp;
	cin >> n;
	int *a=(int*)calloc(6,sizeof(int));
	int *b=(int*)calloc(6,sizeof(int));

	for(int i=1;i<=n;i++)
	{
		cin >> p;
		a[p]++;
	}
	for(int i=1;i<=n;i++)
	{
		cin >> q;
		b[q]++;
	}

		/*
		for(int i=1;i<=5;i++)
			cout << a[i] << "\t" << b[i] << endl;
		cout << endl;
		*/

	for(int j=1;j<=5;j++)
	{
		if(a[j]!=b[j])
			count++;
		if((a[j]+b[j])%2!=0)
			flag=1;
		if(a[j]==b[j])
			a[j]=b[j]=0;
		else if(a[j]>b[j])
		{
			a[j]-=b[j];
			b[j]=0;
		}
		else if(a[j]<b[j])
		{
			b[j]-=a[j];
			a[j]=0;
		}
	}

	if(flag==1)
		cout << "-1" << endl;
	else
	{
		for(int i=1;i<=5;i++)
		{
			for(int j=1;j<=5;j++)
			{
				if(a[j] || b[j])
				{
					if(a[i]==b[j])
					{
						temp=a[i]-((a[i]+b[i])/2);
						if(temp<0)
							temp=-1*temp;
						ans+=temp;
						b[i]=0;
						b[j]=0;
					}
				}
			}
		}

		cout << ans << endl;
	}

}

#include <iostream>
#include <iomanip>
#include <string>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <math.h>
#include <cctype>
#include <climits>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <stdexcept>
#include <exception>
#include <fstream>
#include <algorithm>
#include <ios>
#include <bitset>
#include <sstream>
#include <set>
#include <list>
#include <unordered_map>
#include <unordered_set>

#define test 0
#define pi acos(-1.0)
#define eps 1e-8
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define ABS(x) (((x) > 0) ? (x) : (-(x)))
#define FOR(i,value, n) for(LL i = value ; i< n ;i++)
using namespace std ;

typedef int I ;
typedef short int SI ;
typedef long L ;
typedef long long LL ;
typedef unsigned long long ULL ;
typedef float F ;
typedef double D ;
typedef long double LD ;
typedef char C ;
typedef bool B ;
typedef string S ;
typedef vector<I> VI ;
typedef vector<I>::iterator VIT ;
typedef vector<L> VL ;
typedef vector<L>::iterator VLT ;
typedef vector<LL> VLL ;
typedef vector<LL>::iterator VLLT ;
typedef vector<C> VC ;
typedef vector<S> VS;
typedef vector<C>::iterator VCT ;
typedef pair<LL , LL> PLL;
typedef vector<PLL> VPLL;
typedef vector<VPLL> VVPLL;
typedef set<PLL>::iterator SPLLIT;
typedef unordered_map<C, VC> UMCVC;
template<typename a>
void SWAP(a &b, a &c)
{
    a d = b ;
    b = c ;
    c = d ;
}

LL power(LL a, LL b)
{
    LL result = 1 ;
    while(b)
    {
        if(b&1)
            result = a * result ;
        a *= a ;
        b >>= 1 ;
    }
    return result ;
}
LL gcd(LL a, LL b)
{
    while(b)
    {
        a = a % b;
        SWAP(a,b);
    }
    return a;

}

LL lcm(LL a, LL b)
{
    return (a * (b / gcd(a,b)));
}
int main()
{
#if test
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    LL n;
    scanf("%lld", &n);
    LL input;
    unordered_map<LL, LL> mp;
    mp.reserve(8);
    mp.max_load_factor(0.25);
    FOR(i, 0, 2)
    FOR(j, 0, n)
    {
        scanf("%lld", &input);
        if(i == 0)
        mp[input]++;
        else
            mp[input]--;
    }
    LL ans = 0;
    B check = true;
    for(auto i : mp)
    {
        if((i.second)&1)
        {
            check =false;
            break;
        }
        ans += (ABS(i.second)/2);
    }
    ans /= 2 ;
    if(check)
        printf("%lld\n", ans);
    else
        printf("-1\n");
    return 0;
}

#include <iostream>

using namespace std;

int main()
{
    int n,in,i,div=0,val=0,sum=0;
    int grp1[5]={0,0,0,0,0};
    int grp2[5]={0,0,0,0,0};
    bool sorted=true;

    cin>>n;
    for(i=0;i<n;i++){
        cin>>in;
        grp1[in-1] = grp1[in-1]+1;
    }

    for(i=0;i<n;i++){
        cin>>in;
        grp2[in-1] = grp2[in-1]+1;
    }

    for(i=0;i<5;i++){
        val = grp1[i]-grp2[i];
        if(val<0){
            val = -(val);
        }
        if(val%2==0){
            val = val/2;
            sum = sum+val;
        }
        else{
            cout<<"-1";
            return 0;
        }
    }

        cout<<sum/2;

    return 0;
}

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

int main()
{
    int n, ans, x, cnt;
    int a[10], b[10];
    while(scanf("%d",&n) != EOF) {
        memset(a, 0, sizeof(a));
        memset(b, 0, sizeof(b));
        ans = 0;
        cnt = 0;
        for(int i = 0; i < n; i++) {
            scanf("%d",&x);
            a[x]++;
        }
        //cout << a[4] <<endl;
        for(int i = 0; i < n; i++) {
            scanf("%d",&x);
            b[x]++;
        }
        for(int i = 1; i <= 5; i++)
            if(abs(a[i] - b[i])%2 == 1) {
                ans = 1;break;
            }
            else {
                if(a[i] > b[i]) cnt += a[i] - b[i];
                ans += a[i] - b[i];
            }
        if(ans&1) printf("-1\n");
        else printf("%d\n",cnt/2);
    }
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int g1[10],g2[10];
    int flag[10];
    int n=0;
    cin>>n;
    if(n==1)
    {
        int temp1,temp2;
        cin>>temp1>>temp2;
        if(temp1==temp2)
        {
            cout<<0<<endl;
            return 0;
        }
        else
        {
            cout<<-1<<endl;
            return 0;
        }
    }
    int t=0;
    memset(g1,0,sizeof(g1));
    memset(g2,0,sizeof(g2));
    memset(flag,0,sizeof(flag));
    for(int i=0;i<n;i++)
    {
        cin>>t;
        g1[t]++;
        flag[t]++;
    }
    for(int j=0;j<n;j++)
    {
        cin>>t;
        g2[t]++;
        flag[t]++;
    }
    for(int i=1;i<=5;i++)
    {
        if(flag[i]%2==1)
        {
            cout<<-1<<endl;
            return 0;
        }
    }
    int need1=0,need2=0;
    for(int i=1;i<=5;i++)
    {
        if(g1[i]>g2[i])
        {
            need1+=(g1[i]-g2[i])/2;
        }
    }

    cout<<need1;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

typedef long long int lli;

int main()
{
    //freopen("in.txt","rt",stdin);

    lli num;

    while(cin>>num)
    {
        lli a[num],b[num],pointa[6] = {0},pointb[6] = {0},sum = 0,temp = -1,co = 1;

        for(lli i=0;i<num;i++)
        {
            cin>>a[i];

            if(a[i] == 1)
            {
                pointa[1]++;
            }
            else if(a[i] == 2)
            {
                pointa[2]++;
            }
            else if(a[i] == 3)
            {
                pointa[3]++;
            }
            else if(a[i] == 4)
            {
                pointa[4]++;
            }
            else if(a[i] == 5)
            {
                pointa[5]++;
            }

        }

        for(lli i=0;i<num;i++)
        {
            cin>>b[i];

            if(b[i] == 1)
            {
                pointb[1]++;
            }
            else if(b[i] == 2)
            {
                pointb[2]++;
            }
            else if(b[i] == 3)
            {
                pointb[3]++;
            }
            else if(b[i] == 4)
            {
                pointb[4]++;
            }
            else if(b[i] == 5)
            {
                pointb[5]++;
            }

        }

        for(lli i=1;i<6;i++)
        {

            if(pointa[i] != pointb[i])
            {
                lli temp = (abs(pointa[i]-pointb[i]));

                sum += temp/2;

                if(temp%2==1)
                {
                    co = 0;
                }

            }
        }

        if(sum>=0 && co)
        {
            cout<<sum/2<<endl;
        }
        else
        {
            cout<<"-1"<<endl;
        }

    }

    return 0;
}

#include<bits/stdc++.h>
#define Mo_Ha_Med  std::ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
typedef long long ll;
using namespace std;
int main()
{
    Mo_Ha_Med

    int n,a[100],b[100],s[5],x[5];
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i];
    for(int i=0;i<n;i++)
        cin>>b[i];
    for(int i=1;i<=5;i++)
        s[i-1]=count(a,a+n,i),x[i-1]=count(b,b+n,i);
    for(int i=0;i<5;i++)
        s[i]=abs(s[i]-x[i]);
    int sum=0;
    for(int i=0;i<5;i++)
    {
        if(s[i]%2!=0)
            return cout<<-1<<endl,0;
        sum+=s[i]/2;
    }
    if(sum%2!=0)
            return cout<<-1<<endl,0;
    cout<<sum/2<<endl;
}

#include <stdio.h>
#include <tchar.h>
#include <math.h>
int _tmain(int argc, _TCHAR* argv[])
{
	int a, ai, aii, aiii, aiv, av, bi, bii, biii, biv, bv, x, y, sum;
	int b[101], c[101];
	scanf_s("%d", &a);
	for (int i = 0; i < a; i++)
		scanf_s("%d", &b[i]);
	for (int i = 0; i < a; i++)
		scanf_s("%d", &c[i]);
	ai = 0, aii = 0, aiii = 0, aiv = 0, av = 0, bi = 0, bii = 0, biii = 0, biv = 0, bv = 0, y = 0;
	for (int i = 0; i < a; i++)
	{
		if (b[i] == 1)
			ai++;
		else if (b[i] == 2)
			aii++;
		else if (b[i] == 3)
			aiii++;
		else if (b[i] == 4)
			aiv++;
		else if (b[i] == 5)
			av++;
		if (c[i] == 1)
			bi++;
		else if (c[i] == 2)
			bii++;
		else if (c[i] == 3)
			biii++;
		else if (c[i] == 4)
			biv++;
		else if (c[i] == 5)
			bv++;
	}
	if ((ai + bi) % 2 != 0 || (aii + bii) % 2 != 0 || (aiii + biii) % 2 != 0 || (aiv + aiv) % 2 != 0 || (av + bv) % 2 != 0)
		printf("-1\n");
	else
	{
		sum = (abs(ai - bi) / 2 + abs(aii - bii) / 2 + abs(aiii - biii) / 2 + abs(aiv - biv) / 2 + abs(av - bv) / 2) / 2;
		printf("%d\n", sum);
	}
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define all(c) c.begin(),c.end()
typedef long long ll;
const int N=0;
int n,k,x,t;
string s;
vector<int>v;
int main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r" , stdin);
//	freopen("output.txt", "w" , stdout);
	#endif // ONLINE_JUDGE
	scanf("%d",&n);

	int freqA[10],freqB[10];

	memset(freqA,0,sizeof freqA);
	memset(freqB,0,sizeof freqB);
	for(int i =0;i<n;i++){
		scanf("%d",&x);
		freqA[x]++;
	}

	for(int i =0;i<n;i++){
		scanf("%d",&x);
		freqB[x]++;
	}
	int sum=0;
	for(int i =1;i<=5;i++){
		if((freqA[i]+freqB[i])%2!=0){
			cout << "-1";
			return 0;
		}
		sum+=abs(freqA[i]-freqB[i]);
	}
	cout << sum/4;

	return 0;
}

#include <iostream>
#include <string>
#include <set>
#include <vector>
#include <map>
#include <algorithm>
#include <iterator>
#define ll long long
using namespace std;

int main()
{
	int n, a[6] = {}, b[6] = {}, x, ans = 0, j = 0, j2 = 0;
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> x, a[x]++;
	for (int i = 0; i < n; i++)
		cin >> x, b[x]++;
	for (int i = 1; i < 6; i++)
	{
		if ((a[i] + b[i]) & 1)
		{
			cout << -1;
			return 0;
		}
		j += max(0, a[i] - ((a[i] + b[i]) / 2));
		j2 += max(0, b[i] - ((a[i] + b[i]) / 2));
	}
	cout << (j == j2 ? j : -1);
	return 0;
}

#include <iostream>
#include <bits/stdc++.h>

using namespace std;

int main() {
    int n, s = 0;
//freopen("dist.txt","rt",stdin);
    int ta[5] = {0, 0, 0, 0, 0};
    int tb[5] = {0, 0, 0, 0, 0};
    cin >> n;
    if (n == 1) {
        int a, b;
        cin >> a >> b;
        if (a == b)cout << 0; else cout << -1;
        return 0;
    }
    int nb;
    //int s1=0, s2=0;
    for (int i = 1; i <= n; i++) {
        cin >> nb;
        ta[nb - 1]++;
    }
    for (int i = 1; i <= n; i++) {
        cin >> nb;
        tb[nb - 1]++;
    }

    for (int i = 1; i <= 5; i++) {
        if ((ta[i - 1] + tb[i - 1]) % 2) {
            cout << -1;
            return 0;
        }
        s += abs(ta[i - 1] - tb[i - 1]);
    }
    cout << s / 4;

    return 0;
}

#include<bits/stdc++.h>

using namespace std;

int cnt[2][6];

int main() {

	int n, c;

	cin >> n;

	for( int i = 0; i < n; i ++ ) scanf("%d", &c), cnt[0][c]++;

	for( int i = 0; i < n; i ++ ) scanf("%d", &c), cnt[1][c]++;

	int ans = 0;

	for( int i = 1; i <= 5; i++ ) {

		if( (cnt[0][i] + cnt[1][i] ) % 2 ) { puts("-1");return 0; }

		ans += abs( cnt[0][i] - cnt[1][i] )/2;

	}

	cout << ans / 2 << endl;

	return 0;

}

#include <algorithm>
#include <unordered_map>
#include <map>
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#define DEBUG(x) std::cout << '>' << #x << ':' << x << '\n';
#define PRINT(x) for (int i = 0; i < (int)x.size(); i++) std::cout << x[i] << ' '; std::cout << '\n';
#define io std::ios_base::sync_with_stdio(false);std::cin.tie(NULL);
const int INF = 1<<29;
typedef long long ll;

int solve(std::map<int,int> mp1, std::map<int,int> mp2) {
    int ans = 0;
    for (int i = 1; i <= 5; i++) {
        int cur = std::abs(mp1[i] - mp2[i]);
        if (cur & 1) return -1;
        ans += cur/2;
    }
    return ans/2;
}

int main()
{
	io;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    int n, in;
    std::cin >> n;
    std::map<int,int> mp1, mp2;
    for (int i= 0; i < n; i++) {
        std::cin >> in;
        mp1[in]++;
    }
    for (int i= 0; i < n; i++) {
        std::cin >> in;
        mp2[in]++;
    }
    std::cout << solve(mp1,mp2);

    #ifndef ONLINE_JUDGE
    std::cout << '\n' << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
    #endif
    return 0;
}

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<cstdlib>
#include<string>
#define eps 0.000000001
typedef long long ll;
typedef unsigned long long LL;
using namespace std;
const int N=1000;
int a[N],b[N];
int main(){
    int n;
    while(scanf("%d",&n)!=EOF){
        memset(a,0,sizeof(a));
        memset(b,0,sizeof(b));
        int x;
        for(int i=0;i<n;i++){
            cin>>x;a[x]++;
        }
        for(int i=0;i<n;i++){
            cin>>x;b[x]++;
        }
        int flag=1;
        int f=0;
        for(int i=1;i<=5;i++){
            if(a[i]>b[i]){
                if((a[i]-b[i])%2==1)f=1;
                a[i]=(a[i]-b[i])/2;b[i]=0;}
            if(a[i]<b[i]){
                if((b[i]-a[i])%2==1)f=1;
                b[i]=(b[i]-a[i])/2;a[i]=0;}
            else if(a[i]!=0&&a[i]==b[i]&&b[i]!=0){
                flag=0;a[i]=0;b[i]=0;
            }
        }
        int ans1=0,ans2=0;
        for(int i=1;i<=5;i++){
            ans1=a[i]+ans1;
            ans2=b[i]+ans2;
        }
        if(f==1){
            cout<<-1<<endl;
            continue;
        }
        //cout<<ans1<<" "<<ans2<<endl;
        int ans=max(ans1,ans2);
        if(flag==0&&ans==0){cout<<0<<endl;continue;}
        if(ans==0)cout<<-1<<endl;
        else
            cout<<ans<<endl;
    }

}

#include <iostream>

using namespace std;

int nr1[6], nr2[6];

int main()
{
    int n,i,x,y,sepoate=true,d=0,rez=0;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>x;
        nr1[x]++;
    }

    for(i=1;i<=n;i++)
    {
        cin>>y;
        nr2[y]++;
    }
    for (i = 1; i <= 5; i++)
    {
        d = nr1[i] - nr2[i];
        if (d < 0)
        {
            d = -d;
        }
        if (d % 2 != 0)
        {
            sepoate = false;
        }
        rez += d / 2;
    }
    if (sepoate)
    {
        cout << rez / 2;
    }
    else
    {
        cout << -1;
    }
    return 0;
}

/**
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

#include <bits/stdc++.h>
using namespace std;

#define DEBUG
#ifndef DEBUG
#define endl "\n"
#define log(args...)
#else
#define log(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); logf(_it, args); cout<<endl; }
void logf(istream_iterator<string> it) {
}
template<typename T, typename ... Args>
void logf(istream_iterator<string> it, T a, Args ... args) {
    cout << *it << "=" << a << " ";
    logf(++it, args...);
}
#endif

const double PI = acos(-1);
typedef long long ll;
#define fori(n) for(int i=0; i<int(n); i++)

#define cins(s) string s; cin>>s;
#define cini(i) int i; cin>>i;
#define cinll(l) ll l; cin>>l;
#define cind(d) double d; cin>>d;
#define cinai(a, n) vi a(n); fori(n) { cin>>a[i]; }
#define cinall(a, n) vll a(n); fori(n) { cin>>a[i]; }
#define cinas(s, n) vs s(n); fori(n) { cin>>s[i]; }
#define cinad(a, n) vd a(n); fori(n) { cin>>a[i]; }

typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<string> vs;
typedef vector<ll> vll;

void solve() {
    cini(n);
    cinai(a,n);
    cinai(b,n);

    map<int,int> fa;
    map<int,int> f;

    for(int i=0; i<n; i++) {
        f[a[i]]++;
        f[b[i]]++;
        fa[a[i]]++;
    }

    int ans=0;
    bool ok=true;
    for(auto ent : f) {
        if(ent.second&1)
            ok=false;

        int d=fa[ent.first]-(ent.second/2);
        ans+=abs(d);
    }

    if(!ok)
        cout<<-1<<endl;
    else
        cout<<ans/2<<endl;
}

int main() {
    cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
        solve();
}

#include<bits/stdc++.h>
using namespace std;
int a[100],b[100];
main() {
    int n;
    cin >> n;
    int x;
    for(int i = 1 ; i <= n; i++) {
        cin >> x;
        a[x]++;
    }
    for(int i = 1 ; i <= n; i++) {
        cin >> x;
        b[x]++;
    }

    int temp = 0;
    map<int,int > mp;
    for(int i = 1 ; i <= 5 ; i ++) {
        if(a[i] & 1 and b[i] & 1) {
            if(a[i] < b[i]) {
                temp = (b[i]-a[i])/2;
                if(mp[1])mp[1] += temp;
                else mp[1]= temp;
            } else if(a[i] > b[i]) {
                temp = (a[i] - b[i])/2;
                if(mp[2]) {
                    mp[2] += temp;
                } else mp[2] = temp;
            }
        }
        if(a[i] %2 == 0 and b[i] % 2==0) {
            if(a[i] < b[i]) {
                temp = (b[i] - a[i])/2;
                if(mp[1]) {
                    mp[1]+=temp;
                } else mp[1] = temp;
            } else if(a[i] > b[i]) {
                temp = (a[i] - b[i])/2;
                if(mp[2]) {
                    mp[2] +=temp;
                } else mp[2] =temp;
            }
        }
    }
    if(mp[1] && mp[2] && mp[1] - mp[2] == 0){cout <<mp[1]; return 0;}
    else{
        int cnt1 = 0;
        for(int i = 1 ; i <= 5 ;i++){
            if(a[i] == b[i] and a[i] and b[i]){
             cnt1+=a[i];
            }

        }

        if(cnt1 == n){cout << 0;return 0;}

    }
    cout << -1;
    return 0;

}

#include <iostream>
using namespace std;
int a[10], b[10], balanced[10];
int main() {
	int n, x, ans = 0;
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> x;
		a[x] ++;
		balanced[x] ++;
	}
	for (int i = 0; i < n; i++){
		cin >> x;
		b[x] ++;
		balanced[x] ++;
	}
	for (int i = 1; i < 6; i++){
		if(balanced[i]%2){
			cout << -1;
			return 0;
		}
		else balanced[i] /= 2;
	}
	for(int i = 1; i < 6; i++){
		if (a[i] > balanced[i])ans += a[i] - balanced[i];
	}
	cout << ans;
	return 0;
}

#include <iostream>
#include <valarray>
using namespace std;

valarray<int> c(6);

int main() {
	int n;
	cin >> n;
	for (int i = 0, temp; i < n; ++i) {
		cin >> temp;
		++c[temp];
	}
	for (int i = 0, temp; i < n; ++i) {
		cin >> temp;
		--c[temp];
	}
	if (abs((c % 2)).sum() > 0) {
		cout << -1;
		return 0;
	}
	c /= 2;
	if (c.sum() != 0) {
		cout << -1;
		return 0;
	}
	cout << abs(c).sum() / 2;
	return 0;
}

#include <iostream>
#include <string>
using namespace std;
const int maxn = 110;
int a[maxn],b[maxn];
int sum1[10],sum2[10],sum[10];
int main()
{
	//freopen("in.txt","r",stdin);
	int n,i;
	while(cin>>n)
	{
		memset(sum1,0,sizeof(sum1));
		memset(sum2,0,sizeof(sum2));
		memset(sum,0,sizeof(sum));
		for( i = 0 ; i < n ; i++)
			cin>>a[i],sum1[a[i]]++;
		for( i = 0 ; i < n ; i++)
			cin>>b[i],sum2[b[i]]++;
		for( i = 1 ; i <= 5 ; i++)
		{
			sum[i]=sum1[i]+sum2[i];
		}
		int flag=0;
		int ans=0;
		for( i = 1 ; i <= 5 ; i++)
		{
			if(sum[i]%2!=0)
			{
				flag=1;
				break;
			}
			else if(sum[i]!=0)
			{
				ans+=abs(sum[i]/2-sum1[i]);
			}
		}
		if(flag)cout<<"-1"<<endl;
		else cout<<ans/2<<endl;
	}
	return 0;
}

#include <iostream>
#include <vector>
#include <cstdio>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)

int main()
{
    int n, t;
    scanf("%d", &n);
    vector<int> a(6), b(6);
    rep(i, n)
        scanf("%d", &t), a[t-1]++;
    rep(i, n)
        scanf("%d", &t), b[t-1]++;
    int ans = 0;
    rep(i, 6)
    {
        t = (a[i] - b[i]) < 0 ? -(a[i] - b[i]) : (a[i] - b[i]);
        if(t % 2)
            return printf("-1\n"), 0;
        else
            ans += t / 2;
    }
    printf("%d\n", ans/2);
    return 0;
}

#include <iostream>
#include<map>
using namespace std;

int main() {
	int n,a;
	map<int,int>x,y;
	cin>>n;
	for (int i=0;i<n;i++)
	{cin>>a;  x[a]++;}
	for (int i=0;i<n;i++)
	{cin>>a; y[a]++;}

	int sol=0;

	for (int i=1;i<6;i++)
	{ if ((x[i]+y[i])%2) {cout<<-1; return 0;}
	  sol+=abs((x[i]-y[i])/2);}
cout<<sol/2;
}

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<math.h>

using namespace std;

int main(void)
{
	int N, num, ans = 0;
	bool flag = true;
	int arr1[6] = { 0 };
	int arr2[6] = { 0 };
	scanf("%d", &N);
	for (int i = 0;i < N;i++)
	{
		scanf("%d", &num);
		arr1[num]++;
	}
	for (int i = 0;i < N;i++)
	{
		scanf("%d", &num);
		arr2[num]++;
	}
	for (int i = 1;i <= 5;i++)
	{
		if ((arr1[i] + arr2[i]) % 2)
		{
			flag = false;
			break;
		}
		if (arr1[i] > arr2[i])
			ans += (arr1[i] - arr2[i]) / 2;
	}
	if (!flag)
		printf("-1\n");
	else
		printf("%d\n", ans);
	return 0;
}

#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include<string>

using namespace std;

ifstream in("input.txt");
ofstream out("output.txt");

int main(){
	int n;
	cin >> n;
	vector<int>a(n);
	vector<int>b(n);
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	for(int i = 0; i < n; i++){
		cin >> b[i];
	}
	int ans = 0;
	for(int i = 1; i <= 5; i++){
		int c1 = 0;
		int c2 = 0;
		for(int j = 0; j < n; j++){
			if(a[j] == i)c1++;
			if(b[j] == i)c2++;
		}
		if(abs(c1 - c2) % 2 != 0){
			cout << -1;
			return 0;
		}else{
			ans += abs(c1 - c2) / 2;
		}
	}
	if(ans % 2 != 0)cout << -1;
	else cout << ans/2;
	return 0;
}

#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mod 1000000007
#define all(x) x.begin(),x.end()
#define sorta(x) sort(all(x))
#define test int t;cin>>t;while(t--)
#define input(a,n) for(i=0;i<n;i++)cin>>a[i];
#define forn(i,n) for(int i = 0; i < int(n); i++)
#define forn1(i,n) for(int i = 1; i <= int(n); i++)
#define dwn(i,n) for(int i=(n); --i>=0; )
#define fora(i,a,b) for(int i=a;i<b;i++)
#define line(n) getline(cin,n)
using namespace std ;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector< vector<int> > adjl;
ll gcd (ll x, ll y) {if (y == 0)return x; return gcd(y, x % y);}
void TIME() {
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
}
bool prime (int n ,int i){
    if (i == n) return true;
    if (n%i == 0) return false;
    prime (n , i+1);
}
int main ()
{
  int n , v , arr1[101] = {} , arr2[101] = {} ,counter = 0;
  cin >> n;
  forn(i,n){
    cin >> v; arr1[v]++;
  }
  forn (i,n){
    cin >> v; arr2[v]++;
  }
  forn1(i,5)
    if ((arr1[i]+arr2[i])% 2 != 0){
      return puts("-1"),0;
    }
    else counter+= abs(arr1[i]-arr2[i]);
  if (counter%4 != 0) return puts("-1"),0;
  cout << counter/4 << '\n';
}

#include<stdio.h>
#include <stdlib.h>
#define max 105

int main(){
	int a[max]={0}, b[max]={0}, num1[6]={0}, num2[6]={0};
	int n, i, j, k, subtract;
	subtract = 0;
	scanf("%d", &n);
	for(i=1;i<=n;i++){
		scanf("%d", &a[i]);
		num1[a[i]] += 1;
	}
	for(j=1;j<=n;j++){
		scanf("%d", &b[j]);
		num2[b[j]] += 1;
	}
	for(k=1;k<=5;k++){
		if(((num1[k]+num2[k])%2)!=0){
			printf("-1\n");
			return 0;
		}
		else{
			subtract += (abs(num1[k]-num2[k]))/2;
		}

	}
	printf("%d\n",subtract/2);

}

#include <bits/stdc++.h>
using namespace std;

typedef long long  ll;

#define oo              (1<<30)
#define MOD             1000000007
#define fin              return 0
#define F                first
#define S                second
#define all(x)           x.begin(),x.end()
#define loop(i,n)        for(int i=0;i<n;i++)
#define lop(i,n)         for(int i=1;i<=n;i++)
#define loopv(i,n)       for(int i=n-1;i>=0;i--)

ll conv_to_num(string s){
stringstream ss;
ss<<s;
ll f;
ss>>f;
return f;
}
string conv_to_string(ll s){
stringstream ss;
ss<<s;
string f;
ss>>f;
return f;
}
map<int , int>m1;
map<int , int>m2;
int mark[10000];
int main(){

    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false), cin.tie(NULL);

    int n ;
    cin >> n ;
    int a[n] , b[n];
    loop(i,n){
    cin >> a[i];
    m1[a[i]]++;
    }
    loop(i,n){
    cin >> b[i];
    m2[b[i]]++;
    }
    int ans=0;
   loop(i,n){
   int x=a[i];
   if(!mark[x]){
   int s1=m1[x];
   int s2=m2[x];
   if(abs(s1-s2)%2==0){
   ans+= abs(s1-s2)/2;
   }
   else {cout<<-1;fin;}
   mark[x]=1;
   }
   }

loop(i,n){
   int x=b[i];
   if(!mark[x]){
   int s1=m1[x];
   int s2=m2[x];
   if(abs(s1-s2)%2==0){
   ans+= abs(s1-s2)/2;
   }
   else {cout<<-1;fin;}
   mark[x]=1;
   }
   }

cout << ans/2;
return 0;
}

#include <iostream>
#include <complex>
using namespace std;

int main(){
	int n,b[7],a,sum=0;
	cin>>n;
	for (int x=1; x<=5; x++){
		b[x]=0;
	}
	for (int x=1; x<=n; x++){
		cin>>a;
		b[a]++;
	}
	for (int x=1; x<=n; x++){
		cin>>a;
		b[a]--;
	}
	for (int x=1; x<=5; x++){
		if (abs(b[x])%2==1) {sum=-1;break;}
		sum=sum+abs(b[x]/2);
	}
	if (sum!=-1) sum/=2;
	cout<<sum<<endl;
}

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <queue>
#include <iomanip>
#include <cstdio>
#include <limits>
#include <cmath>
#include <cstdlib>
#include <string.h>
#include <ctime>
#include <assert.h>

using namespace std;

#define VI vector<int>
#define VVI vector<VI >
#define VB vector<bool>
#define VVB vector<VB >
#define VS vector<string>
#define PII pair<int, int>
#define VPII vector<pair<int, int> >
#define REP(var, startFrom, endTo) for(int var = startFrom; var < (int)endTo; ++var)

template <typename T>
inline const T MAX(T a, T b) { return ((a) > (b) ? (a) : (b)); }
template <typename T>
inline const T MIN(T a, T b) { return ((a) > (b) ? (b) : (a)); }
template <typename T>
inline const T ABS(T a) { return (((a) > 0) ? (a) : (-(a))); }

int n;
int solve(VI& scoresA, VI& scoresB)
{
	int ans = 0;
	for (int i = 1; i <= 5; ++i)
	{
		int sum = scoresA[i] + scoresB[i];
		if (sum & 1)
			return -1;
		ans += ABS(scoresA[i] - scoresB[i]) / 2;
	}
	return ans / 2;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
#ifndef ONLINE_JUDGE
	freopen("tmp.in", "r", stdin);
	//	freopen("tmp.out", "w", stderr);
#endif
	cin >> n;
	VI scoresA, scoresB;
	scoresA = scoresB = VI(6);
	REP(i, 0, n)
	{
		int score;
		cin >> score;

		++scoresA[score];

	}
	REP(i, 0, n)
	{
		int score;
		cin >> score;

		++scoresB[score];
	}

	cout << solve(scoresA, scoresB) << endl;

	return 0;
}

#include "bits/stdc++.h"
using namespace std;

int main(){
	#define int long long int
	int numStd, sum=0,j=1, cont=0;
	bool flag =1;
	scanf("%lld", &numStd);
	int stdA[numStd];
	int stdB[numStd];
	int qtdA[6]={0};
	int qtdB[6]={0};
	for(int i=0;i<numStd;i++){
		scanf("%lld",&stdA[i]);
		qtdA[stdA[i]]++;
	}
	for(int i=0;i<numStd;i++){
		scanf("%lld",&stdB[i]);
		qtdB[stdB[i]]++;
	}
	while(j<6 && flag){
		sum=qtdA[j]+qtdB[j];
		if(sum%2==1){
			cout<<"-1\n";
			return 0;
		}
		else{
			cont+= abs(qtdA[j]-qtdB[j])/2;
			j++;
		}
	}
	cout<<cont/2<<"\n";
}

#include <cstdio>
#include <string.h>
#include <algorithm>
#include <string>
#include <queue>
#include <map>
#include <stack>
#include <math.h>
#include <vector>
using namespace std;
#define mod 1000000007
#define inf 0x3f3f3f3f
#define ll long long
typedef pair<int,int>p;
int main()
{
 int n,t,sum=0,flag=0;
 scanf("%d",&n);
 int c[6]={0},b[6]={0};
 for(int i=1;i<=n;i++)
 {
     scanf("%d",&t);
     b[t]++;
     c[t]++;
 }
 for(int i=1;i<=n;i++)
 {
     scanf("%d",&t);
     c[t]++;
 }
 for(int i=1;i<=5;i++)
 {
   if(c[i]%2==1) flag=1;
   if(c[i]/2>b[i])  sum+=c[i]/2-b[i];
   else sum+=b[i]-c[i]/2;
 }
 if(flag==1) printf("-1\n");
 else printf("%d\n",sum/2);
    return 0;
}

#include<iostream>
#include<vector>
using namespace std;
void main() {
	vector<int> a(6);
	vector<int> b(6);
	int n; cin >> n;
	int d;
	for (int i = 0; i < n; i++) {
		cin >> d;
		a[d]++;
	}
	for (int i = 0; i < n; i++) {
		cin >> d;
		b[d]++;
	}
	int sum = 0;
	for (int i = 1; i < 6; i++) {
		if ((a[i] + b[i]) % 2) {
			cout << -1;
			return;
		}
		sum += abs(a[i] - b[i]) / 2;
	}
	cout << sum /2;
}

#include <iostream>
#include <string>
#include <deque>
#include <algorithm>
#include <iterator>
#include <sstream>
#include <locale>
#include <Windows.h>
#include <cmath>
#include <string.h>
#include <stdio.h>
#include <conio.h>
#include <fstream>
#include <math.h>
#include <stdlib.h>
#include <vector>

using namespace std;

int main(){
//	freopen ("in.txt","r",stdin);
//	freopen ("out.txt","w",stdout);

	int a[10]={0},b[10]={0},c[10]={0};
	int n,q,k=0,fl=0;

	cin>>n;
	for (int i=0; i<n; i++)
	{
		cin>>q;
		a[q]+=1;
	}

	for (int i=0; i<n; i++)
	{
		cin>>q;
		b[q]+=1;
	}

	for (int i=0; i<7; i++)
	{
		if ((a[i]+b[i])%2==0)
		{
			k+=abs((a[i]-b[i])/2);
		}
		else
		{
			cout<<"-1";
			return 0;
		}
		if (a[i]!=b[i]) fl=1;
	}

	if (k==0 && fl==1) cout<<"-1"; else cout<<k/2;

}

#include<iostream>
#include<stdio.h>
using namespace std;
int a[105],b[105];
int u[6],v[6];
int d[6];
int ans1=0,ans2=0;
int ans=0;
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		u[a[i]]++;
	}
	for(int i=1;i<=n;i++){
		scanf("%d",&b[i]);
		v[b[i]]++;
	}
	for(int i=1;i<=5;i++){
		d[i]=u[i]-v[i];
		if(d[i]%2!=0){
			printf("-1\n");
			return 0;
		}
		if(d[i]>0){
			ans1+=d[i]/2;
		}
		else ans2+=(-d[i])/2;
	}
	if(ans1!=ans2)printf("-1\n");
	else printf("%d\n",ans1);
}

#include <iostream>
using namespace std;
int main(){
    int n;
    int mas[100];
    int mass[100];
    int pyat=0,chetiri=0,tri=0,dwa=0,odin=0;
    int pyat2=0,chetiri2=0,tri2=0,dwa2=0,odin2=0;
    cin >> n;
    for (int i=0;i<n;i++)
        {
        cin >> mas[i];
        if (mas[i] == 5) pyat ++;
        if (mas[i] == 4) chetiri ++;
        if (mas[i] == 3) tri ++;
        if (mas[i] == 2) dwa ++;
        if (mas[i] == 1) odin ++;
        }
    for (int j=0;j<n;j++)
        {
        cin >> mass[j];
        if (mass[j] == 5) pyat2 ++;
        if (mass[j] == 4) chetiri2 ++;
        if (mass[j] == 3) tri2 ++;
        if (mass[j] == 2) dwa2 ++;
        if (mass[j] == 1) odin2 ++;
        }
    int s = 0;

//    cout << "DEBUG" << endl;
//    cout << pyat2 << pyat << endl;
//    cout << chetiri2 << chetiri << endl;
//    cout << tri2 << tri << endl;
//    cout << dwa2 << dwa << endl;
//    cout << odin2 << odin << endl;
//     cout << "END DEBUG" << endl;

    if ((pyat2 + pyat) % 2 != 0) {
            cout << -1;
            return 0;
    } else s += max(pyat2, pyat)-(pyat2 + pyat) / 2;
    if ((chetiri2 + chetiri) % 2 != 0) {
            cout << -1;
            return 0;
    } else s += max(chetiri2, chetiri)-(chetiri2 + chetiri) / 2;
    if ((tri2 + tri) % 2 != 0) {
            cout << -1;
            return 0;
    } else s += max(tri2, tri)-(tri2 + tri) / 2;
    if ((dwa2 + dwa) % 2 != 0) {
            cout << -1;
            return 0;
    } else s += max(dwa2, dwa)-(dwa2 + dwa) / 2;
    if ((odin2 + odin) % 2 != 0) {
            cout << -1;
            return 0;
    } else s += max(odin2, odin)-(odin2 + odin) / 2;
    cout << s/2;
    return 0;
}

#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int a[6],b[6];
int main()
{
    int n,sum=0;
    cin>>n;
    for(int i=1;i<=2*n;i++)
    {
        int x;
        cin>>x;
        if(i<=n)
            a[x]++;
        else b[x]++;
    }
    for(int i=1;i<=5;i++)
    {
        if((a[i]+b[i])%2==1){sum=-2;break;}
        sum+=abs(a[i]-b[i])/2;
    }
    cout<<sum/2<<endl;
    return 0;
}

#include<iostream>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
using namespace std;
int main()
{

    int x[5],y[5],n,i,co=0,temp;
    cin >> n;
    memset(x,0,sizeof(x));
    memset(y,0,sizeof(y));
    for(i=0 ; i<n ; i++){
        cin >> temp;
        x[temp-1]++;
    }
    for(i=0 ; i<n ; i++){
         cin >> temp;
        y[temp-1]++;
    }

    for(i=0 ; i<5 ; i++){
        if((x[i]+y[i])%2)
        {
            cout << -1 << endl;
            return 0;
        }
        co += abs(x[i]-y[i])/2;
    }

        cout << co/2 << endl;
    return 0;
}

#include<bits/stdc++.h>
#include<math.h>
using namespace std;

const int N = 105;
int a[N],b[N],aa[6],bb[6];
int main()
{
    int n;
    int k=0;
    cin>>n;
    for(int i=0;i<n;i++)
       cin>>a[i];
    for(int i=0;i<n;i++)
       cin>>b[i];
    for(int i=0;i<n;i++)
       {
           aa[a[i]]++;
           bb[b[i]]++;
       }
       int i;
       for( i=1;i<=5;i++)
       {   int m=abs(aa[i]-bb[i]);
           if(m%2==0 ) k=k+m/2;
           else  {cout<<"-1"<<endl;  break;}
        }
        if(i==6) cout<<k/2<<endl;

   return 0;

}

#include<bits/stdc++.h>
#define ll long long int
using namespace std;
bool comp(int a, int b)
{
    return (a < b);
}
int main()
{
    ll n,i,j,ans=0;
    cin>>n;
    ll a,b,hasha[6],hashb[6];
    memset(hasha,0,sizeof(hasha));
    memset(hashb,0,sizeof(hashb));
    for(i=0;i<n;i++)
    {
        cin>>a;
        hasha[a]++;
    }
    bool flag=true;
    for(i=0;i<n;i++)
    {
        cin>>b;
        hashb[b]++;
    }
    for(i=1 ;i<=5;i++)
    {
        if(((hasha[i]+hashb[i])%2!=0))
        {
            flag=false;
            break;
        }
        ans+=(hasha[i]+hashb[i])/2-min(hasha[i],hashb[i]);
    }
    if(flag==false)
        cout<<-1<<endl;
    else
        cout<<ans/2<<endl;

    return 0;
}

#include<bits/stdc++.h>

using namespace std;

#define forn(i,n) for(i=0;i<n;++i)
#define for1(i,n) for(i=1;i<=n;++i)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fill(x,b) memset((x),b,sizeof((x)))
#define fill2D(x,r,c,b) memset((x),b, sizeof(x[0][0]) * r * c)

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef vector<vs> vvs;

const int mod = 1e9 + 7;
clock_t t1,t2;

ll binPow(ll a, ll b){ll x = 1, y = a;while (b){if (b & 1)x = (x * y) % mod;y = (y*y) % mod;b >>= 1;}return x % mod;}

ll inverserEuler(int n){return binPow(n, mod-2);}

ll C(int k, int n){vll f(n+1,1);for(int i = 2;i<=n;i++)f[i] = (f[i-1]*i)%mod;return (f[n] * ((inverserEuler(f[k]) * inverserEuler(f[n-k]))%mod)%mod)%mod;}

/* Extend Euclid: ax + by = c;
ll x, y;

void extendEuclid(ll a, ll b){if(b == 0){x = 1;y = 0;return;}extendEuclid(b,a%b);ll x1 = y, y1 = x - (a/b) * y;x = x1;y = y1;}
// nghiem : x + (b/d)*k, y - (a/d) * k;
*/
/*--------------------------------------------------------------------------------------------------*/

const int maxn = 100;

int n, a[maxn], b[maxn];

void trunghieu()
{
    cin>>n;
    int i,j;
    map<int,int> cntA, cntB;
    forn(i,n)
        cin>>a[i],
        cntA[a[i]]++;
    forn(i,n)
        cin>>b[i],
        cntB[b[i]]++;
    int ans = 0;
    for1(i,5)
    {
        if((cntA[i] + cntB[i])%2)
        {
            cout<<-1;
            return;
        }
        ans+= abs(cntA[i] - cntB[i])/2;
    }
    cout<<ans/2;
}

int main()
{
    cerr << "Program is running" << endl;
    t1 = clock();
    ios::sync_with_stdio(false);
    cin.tie();
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
        //freopen("output.txt","w",stdout);
    #endif
    trunghieu();
    t2 = clock();
    float diff ((float)t2-(float)t1);
    float seconds = diff / CLOCKS_PER_SEC;
    cerr << "\nRunning in " << seconds << " seconds" << endl;
    return 0;
}

// Best practice

#include<bits/stdc++.h>

#define int         long long
#define pb          push_back
#define pf          emplace_front
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define pii 		pair<int,int>
#define psi 		pair<string,int>
#define vi 			vector<int>
#define vpii  		vector<pii>
#define vvi 		vector<vi>
#define sz(x)	    (int)(x).size()
#define x           first
#define y           second
#define endl        '\n'
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MOD         1000000007
#define hell        998244353
#define output(x)   cout << (x ? "YES" : "NO")<<endl;
using namespace std;

// Code from Here -------------------------------------------------------------------------------

signed main() {
	tezz

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int n,p;
	cin >> n;
	map<int,int> mp,mpp;
	for(int i=0; i<n; i++){
		cin >> p;
		mp[p]++;
	}
	for(int i=0; i<n; i++){
		cin >> p;
		mpp[p]++;
	}
	int ans=0;
	for(int i=1; i<=5; i++){
		int x = abs(mp[i]-mpp[i]);
		if(x&1){
			cout << -1;
			return 0;
		}
		ans+=x;
	}
	// cout << ans << endl;
	if(ans%4==0)cout << ans/4;
	else cout << -1 << endl;

	return 0;
}

#include <iostream>
#include <cmath>

using namespace std;

int main()
{
	int n = 0, k = 0, sum = 0;
	char a;
	int mark[2][101] = { 0 };

	cin >> n;
	for (int i = 1;i <= 2 * n; i++)
	{
		if (i <= n)
		{
			cin >> k;
			++mark[0][k];
		}
		else
		{
			cin >> k;
			++mark[1][k];
		}
	}
    k = 0; n = 0;

	for (int i = 1; i <= 5; i++)
	{
		n = sum;
		sum += mark[0][i] - mark[1][i];
		k += abs(n - sum / 2);
	}

	if (sum == 0)
		cout << k / 2;
	else
		cout << -1;

	return 0;
}

#include <iostream>

using namespace std;

int abs(int x){
    return x<0? -x:x;
}

int main(){
    int n, a[5]={0},b[5]={0},t,i;
    cin>>n;
    for(i=0; i<n; i++){
        cin>>t;
        a[t-1]++;
    }
    for(i=0; i<n; i++){
        cin>>t;
        b[t-1]++;
    }
    int s=0;
    for(i=0;i<5;i++){
        b[i]+=a[i];
        if(b[i]%2==1){
            s=1;
            return 0;
        }
        s += abs(a[i] - b[i]/2);
    }
    if(s%2==0)
    cout<<s/2;
    else
    cout<<-1;
    return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include<math.h>
int main()
{
    int n;
    int a[111]={0},b[111]={0},cha[111]={0};
    int i,j;
    int suma=0,sumb=0;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
        suma+=a[i];
    }
     for(i=0;i<n;i++){
        scanf("%d",&b[i]);
        sumb+=b[i];
    }
    int num=0;
    int t;
    if(n==1&&a[0]!=b[0]){
        printf("-1\n");
        return 0;
    }
    for(i=0;i<n;i++){
        if(a[i]<1||a[i]>5||b[i]<1||b[i]>5)
        {
            printf("-1\n");
            return 0;
        }
    }
///paixu
int max,kmax;
for(i=0;i<n;i++){
        max=abs(a[i]-b[i]);
        kmax=i;
    for(j=i+1;j<n;j++){
        if(abs(a[j]-b[j])>max){
            max=abs(a[j]-b[j]);
            kmax=j;
        }

    }
    if(kmax!=i){
        t=a[kmax];
        a[kmax]=a[n-1-i];
        a[n-1-i]=t;
        t=b[kmax];
        b[kmax]=a[n-1-i];
        b[n-1-i]=t;
    }
}

        for(i=0;suma-sumb!=0&&i<n;i++){
            if(a[i]==b[i])
                continue;
                if(suma-sumb>0){
                    if(a[i]-b[i]>0){
                        t=a[i];
                        a[i]=b[i];
                        b[i]=t;
                        num++;
                        suma-=b[i];
                        suma+=a[i];
                        sumb-=a[i];
                        sumb+=b[i];
                    }
                }
                else{
                    if(a[i]-b[i]<0){
                        t=a[i];
                        a[i]=b[i];
                        b[i]=t;
                        num++;
                        suma-=b[i];
                        suma+=a[i];
                        sumb-=a[i];
                        sumb+=b[i];
                }

            }
        }
        printf("%d\n",num);
    return 0;
}

#include<bits/stdc++.h>

using namespace std;
int main()
{
    int n;
    while(cin>>n)
    {
        int arr1[200]={0},arr2[200]={0},arr[250]={0},k;
         int flag=0,ans=0;
        for(int i=0;i<n;i++)
        {
            cin>>k;
            arr1[k]++;
        }
        for(int i=0;i<n;i++)
        {
            cin>>k;
            arr2[k]++;
        }
        for(int i=1;i<=5;i++)
        {
            if((arr1[i]+arr2[i])%2!=0){
                flag=1;
            }

        }
        for(int i=1;i<=5;i++)
        {
            arr[i]=abs(arr1[i]-arr2[i]);
        }

        for(int i=1;i<=5;i++)
        {

            int diff=arr[i];
            arr[i]=0;
            ans+=diff/2;
            for(int j=i+1;j<=5;j++)
            {

                if(arr[j]!=0 && diff!=0){
                if(arr[j]>=(diff))
                {
                    arr[j]-=(diff);
                    diff=0;
                }
                else
                {
                    diff-=arr[j];
                    arr[j]=0;

                }
                if(diff<0)
                    diff=0;
                }
            }
        }

        if(flag)
            cout<<"-1"<<endl;
        else
            cout<<ans<<endl;
    }
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[6]={0},b[6]={0};
int n;
int main()
{
    scanf("%d",&n);
    for(int i=1,x;i<=n;i++)
    {
        scanf("%d",&x);
        a[x]++;
    }
    for(int i=1,x;i<=n;i++)
    {
        scanf("%d",&x);
        b[x]++;
    }
    int cnt=0;
    for(int i=1;i<=5;i++)
    {
        if(a[i]<b[i]) continue;
        if(abs(a[i]-b[i])==1)
        {
            puts("-1");
            return 0;
        }
        cnt+=(a[i]-b[i])/2;
    }
    printf("%d\n",cnt);
    return 0;
}

#include<cstdio>
#include<iostream>
#include<cstdlib>
using namespace std;

int main(){
int n;
int a[100],b[100];
cin >>n;
for(int i =0;i<n;i++){
cin >> a[i];
}
for(int i =0;i<n;i++){
cin >> b[i];
}
int c[5],d[5];

for(int k=1;k<=5;k++){
    c[k] =0;
    d[k] =0;
}

for(int i =0;i<n;i++){
    for(int j=1;j<=5;j++){
        if(a[i] == j)
        c[j] ++;
        if(b[i] == j)
        d[j] ++;
    }
}

int ans = 0;
int ans1 =0;

for(int i =1;i<=5;i++){
if(c[i] - d[i] > 0){
    ans = ans + c[i] -d[i];
}
if(c[i] - d[i] < 0)
{
    ans1 = ans1 + c[i] -d[i];
}
}

if((abs(ans) == abs(ans1)) && (ans%2==0)){
cout << abs(ans/2);
} else{

    cout << -1;
}
return 0;
}

#include<bits/stdc++.h>
using namespace std;
int a[500];
int b[500];
int main(){
  int n,i,j,k,l,m;
  cin>>n>>m;
  for(i=1;i<=n;i++){
    cin>>a[i];
    b[a[i]]=1;
  }
  int sum=0;
  for(i=0;i<m;i++){
    if(b[i]==0)
     sum++;
  }
  if(b[m]==1)
   sum++;
   cout<<sum<<endl;;
}

#include <bits/stdc++.h>

using namespace std;
 int sum[2][6];
int main()
{
    long long a;
    cin>>a;
    for(int g=0;g<2;g++)
    {
        for(int i=0;i<a;i++)
        {
            int m;
            cin>>m;
            sum[g][m]++;
        }
    }
    long long k=0,n=0;
    for(int i=1;i<=5;i++)
    {
        if(sum[i][0]>sum[i][1])
        {
            k+=sum[i][0]-sum[i][1];
        }
        if(sum[i][1]>sum[i][0])
        {
            n+=sum[i][1]-sum[i][0];

        }
        if(n%2==1||k%2==1)
        {
            cout<<-1;
            return 0;
        }
    }
    if(k==n)
    {
        cout<<k;
        return 0;
    }
    cout<<-1;
}

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
ll a[5+1],b[5+1];

main()
{

    ll n;

    cin >> n;

    for(ll i = 0;i < n;i++)
    {

        ll temp;

        cin >> temp;
        a[temp]++;

    }
    for(ll i = 0;i < n;i++)
    {

        ll temp;

        cin >> temp;
        b[temp]++;

    }

    bool flag = true;
    ll ans = 0;

    for(ll i = 1;i < 5;i++)
    {

        if((a[i] + b[i])%2)
        {

            flag = false;
            break;

        }
        ll k = (a[i] + b[i])/2;

        ans +=1;

    }

    if(!flag)
        cout << -1;
    else{

        cout << ans;
    }

}

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
int cnt[10],n,in;
int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&in);
		cnt[in]++;
	}
	for(int i=0;i<n;i++){
		scanf("%d",&in);
		cnt[in]--;
	}
	int res=0;
	for(int i=1;i<=5;i++){
		if(cnt[i]&1){
			res=-1;break;
		}
		res+=abs(cnt[i])/2;
	}
	printf("%d\n",res);
	return 0;
}

#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int m[2][6];
int sum[6];
int main()
{
    int res = 0,n,temp;
    memset(sum,0,sizeof(sum));
    memset(m,0,sizeof(m));
    scanf("%d",&n);
    for(int i=0; i<2; i++){
        for(int j=0; j<n; j++){
            scanf("%d",&temp);
            m[i][temp]++;
            sum[temp]++;
        }
    }
    bool flag = true;
    for(int i=1; i<=6; i++){
        if(sum[i]%2 == 1){
            flag = false;
            break;
        }
        res = res + abs(m[0][i]-sum[i]/2);
    }
    if(res%2 == 1 && !flag) printf("-1");
    else    printf("%d",res/2);
    return 0;
}

#include<bits/stdc++.h>
#define Mo_Ha_Med  std::ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
typedef long long ll;
using namespace std;
int main()
{
    Mo_Ha_Med

    int n,a[101],b[101],sum=1,s=1;
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i];
	for(int i=0;i<n;i++)
		cin>>b[i];
    if(n==1&&a[0]==b[0])
        return cout<<0<<endl,0;
    if (n==2)
		return cout<<-1<<endl,0;
	sort(a,a+n);
	sort(b,b+n);
	for(int i=1;i<n;i++)
		if(a[i]==a[i-1])
			sum++;
	for(int i=1;i<n;i++)
		if(b[i]==b[i-1])
			s++;
	if(a[n-1]==a[n-2])
		sum++;
	if(b[n-1]==b[n-2])
		s++;
	sum/=2,s/=2;
	cout<<min(s,sum)<<endl;
}

#include<bits/stdc++.h>
using namespace std;

map<int,int>mp;
map<int,int>mp2;

int main()
{
   // freopen("in.txt","r",stdin);
    int n,val,ans=0;
    scanf("%d",&n);

    for(int i=0; i<n; i++)
    {
       scanf("%d",&val);
       mp[val]++;
    }

    for(int i=0; i<n; i++)
    {
       scanf("%d",&val);
       mp2[val]++;
    }

    for(int i=1; i<=5; i++)
    {
      if(mp[i]!=0){
      int a=abs(mp[i]-mp2[i]);
      if(a>0)
        ans+=a/2;
      }
    }

    if(ans!=0)
       printf("%d\n",ans);
    else
        printf("-1\n");

    mp.clear();
    mp2.clear();

    return 0;
}

//
//  main.cpp
//  ervb
//
//  Created by Kanak Gautam on 21/04/20.
//  Copyright © 2020 Kanak Gautam. All rights reserved.
//

#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#define pb push_back
using namespace std;
typedef long long int lli;
typedef long long ll;
int main ()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    lli n;cin>>n;
    vector <lli> a(n,0),b(n,0),x(6,0),y(6,0);
    for(lli i=0;i<n;i++)
    {
        cin>>a[i];
        x[a[i]]++;
    }
    for(lli i=0;i<n;i++)
    {
        cin>>b[i];
        y[b[i]]++;
    }
    lli c=0;
    for(lli i=1;i<=5;i++)
    {
        if(x[i]>y[i])
        {
            if((x[i]-y[i])%2==1)
            {
                cout<<-1<<endl;
                exit(0);
            }
            //cout<<"i"<<" "<<i<<endl;
            //cout<<x[i]<<" "<<y[i]<<endl;
            c+=(x[i]-y[i])/2;
            //cout<<c<<endl;
        }
    }
    if(c==0)
    {
        for(lli i=1;i<=5;i++)
        {
            if(x[i]!=y[i])
            {
                cout<<-1<<endl;
                exit(0);
            }
        }
    }
    cout<<c<<endl;
}

#include<stdio.h>
#include<iostream>
#include<math.h>
#include<string>
#include<algorithm>

using namespace std;

int a[100000];
int b[100000];
int x, y, z;
unsigned long long nr;
int n;

int main()
{
	scanf("%d", &n);

	for (int i = 1; i <= n; i++)
	{
		scanf("%d", &x);
		a[x]++;
	}

	for (int i = 1; i <= n; i++)
	{
		scanf("%d", &x);
		b[x]++;
	}

	int k = 1;
	for (int i = 1; i <= 5; i++)
	{
		if (a[i] + b[i] % 2 == 1)
			k = 0;
	}

	if (k == 0)
	{
		k = -1;
		printf("%d\n",k);
	}
	else
	{
		for (int i = 1; i <= 5; i++)
		{
			nr += abs(a[i] - b[i]);
		}
		cout << nr / 4;
	}

	return 0;
}

#include<iostream>
#include<cmath>
using namespace std;

int hasil(int jum[]){
    int sum=0;
    for(int i=1;i<6;i++){
        if(jum[i]%2==1){
            return -1;
        }
        sum+=abs(jum[i]);
    }
    return (sum/4);
}

int main(){
    int n;
    int m;
    int jum[6]={0};
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>m;
        jum[m]++;
    }
    for(int i=0;i<n;i++){
        cin>>m;
        jum[m]--;
    }

    cout<<hasil(jum);
}

#include <iostream>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <assert.h>
#include <deque>
using namespace std;

typedef unsigned long long UL;
typedef long long LL;
#define LP(i, a, b) for (int i = int(a); i < int(b); i++)
#define LPE(i, a, b) for (int i = int(a); i <= int(b); i++)
typedef pair<int, int> PII;
//typedef vector<vector<PII> > WAL;
typedef vector<vector<int> > SAL;
#define Ep 1e-7

#define INF 1e9
/*
 calculate each digits count
 total exchange = pos delta/2
 each delta  % 2 = 0
 */

int const MaxSize = 1e5 + 1;

int ca[6], cb[6], n;

int main() {

	ios_base::sync_with_stdio(false);
	//freopen("/Users/george/A_1.in", "r", stdin);

	cin >> n;

	LP(i, 0, n)
	{
		int g;
		cin >> g;

		ca[g]++;
	}

	LP(i, 0, n)
	{
		int g;
		cin >> g;

		cb[g]++;
	}

	int ans = 0;

	LPE(g, 1, 5)
	{
		int delta = ca[g] - cb[g];

		if (delta > 0) {

			if (delta % 2) {
				cout << -1;
				return 0;
			} else {
				ans += delta / 2;
			}
		} else if (delta % 2) {
			cout << -1;
		}
	}

	cout << ans;

	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int
#define f(i,a,n) for(ll i=a;i<n;i++)
#define vi vector<int>
#define MAX 500001
#define vi_ll vector<long long int>
#define mod 998244353
#define fi first
#define se second
#define ull unsigned long long int
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define all(a) a.begin(),a.end()
#define mp make_pair
const double pi = acos(-1);
int prime[10000001];
const int N=2e5+5;
ll max(ll a,ll b)
{
	if(a<b)a=b;
	return a;
}
ll min(ll a,ll b)
{
	if(a<b)return a;
	return b;
}
ll lcm(ll a,ll b)
{
	return ((a*b)/__gcd(a,b));
}
void init()
{
	fill(prime,prime+10000001,1);
	prime[0]=1,prime[1]=1;
	int no=sqrt(10000001);
	f(i,2,no+1)
	{
		if(prime[i])
		{
			for(int j=2;i*j<=10000001;j++)
			{
				prime[i*j]=0;
			}
		}
	}
	return;
}
bool mycomp(const pair<ll,ll> &a,const pair<ll,ll> &b)
{
	return a.se<b.se;
}
int main()
{
	FIO
	ll n,no; cin>>n;
	vi_ll a(6),b(6); ll sum[6]={0};
	f(i,0,n)
	{
		cin>>no;
		a[no]++;
	}

	f(i,0,n)
	{
		cin>>no;
		b[no]++;
	}

	f(i,1,6)
	sum[i]=a[i]+b[i];

	f(i,1,6)
	{
		if((a[i]==0&&b[i]!=0&&b[i]%2)||(b[i]==0&&a[i]!=0&&a[i]%2))
		{
			cout<<"-1\n";
			return 0;
		}
	}

	ll ans=0;
	f(i,1,6)
	{
		if(a[i]>b[i])
		{
			no=abs(a[i]-(sum[i])/2);
			ans+=no;
			a[i]-=no;
			b[i]+=no;

			ll j=0;
			while(j<6&&no>0&&j!=i)
			{
				if(a[j]<b[j])
				{
					if(no<(b[j]-a[j]))
					{
						a[j]+=no;
						b[j]-=no;
						no=0;
					}

					else
					{
						ll no2=b[j]-a[j];
						a[j]+=no2;
						b[j]-=no2;
						no-=no2;
					}
				}
				j++;
			}

		}
	}
	cout<<ans<<endl;
}

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int g1[105],g2[105];
    int flag[10];
    int n=0;
    cin>>n;
    if(n==1)
    {
        int temp1,temp2;
        cin>>temp1>>temp2;
        if(temp1==temp2)
        {
            cout<<0<<endl;

        }
        else
        {
            cout<<-1<<endl;
        }
    }
    int t=0;
    memset(g1,0,sizeof(g1));
    memset(g2,0,sizeof(g2));
    memset(flag,0,sizeof(flag));
    for(int i=0;i<n;i++)
    {
        cin>>t;
        g1[t]++;
        flag[t]++;
    }
    for(int j=0;j<n;j++)
    {
        cin>>t;
        g2[t]++;
        flag[t]++;
    }
    for(int i=1;i<=5;i++)
    {
        if(flag[i]%2==1)
        {
            cout<<-1<<endl;
            return 0;
        }
    }
    int need1=0,need2=0;
    for(int i=1;i<=5;i++)
    {
        if(g1[i]>g2[i])
        {
            need1+=(g1[i]-g2[i])/2;
        }
    }
    for(int j=1;j<=5;j++)
    {
        if(g2[j]>g1[j])
        {
            need2+=(g2[j]-g1[j])/2;
        }
    }
    if(need1==need2)
    {
        cout<<need1<<endl;
    }
    else
    {
        cout<<-1<<endl;
    }
    return 0;
}

#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <climits>
#include <algorithm>
#include <map>
#include <set>
#include <cstdlib>
#include <iterator>
#include <queue>
#include <ctime>
#include <stack>
#include <list>
#include <deque>

using namespace std;

#define PI 3.14159265
#define INF LLONG_MAX
typedef long long ll;
typedef unsigned u;

int n,ans;
int a[200],b[200];
map<int,int> c,d;

int main()
{
    ios_base::sync_with_stdio(false);
    #ifdef LOCAL
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif

    cin>>n;
    for (int i=1;i<=n;i++)
    {
        cin>>a[i];
        c[a[i]]++;
    }
    for (int i=1;i<=n;i++)
    {
        cin>>b[i];
        d[b[i]]++;
    }

    for (int i=1;i<=5;i++)
    {
        if ((c[i]+d[i])%2)
        {
            cout<<-1;
            return 0;
        }
    }

    sort(a+1,a+n+1);
    sort(b+1,b+n+1);

    for (int i=1;i<=n;i++)
    {
        int mx1=0,mxi1=0,mx2=0,mxi2=0;
        for (int j=1;j<=5;j++)
        {
            if (c[j]!=d[j])
            {
                if (c[j]>mx1)
                {
                    mx1=c[j];
                    mxi1=j;
                }
                if (d[j]>mx2)
                {
                    mx2=d[j];
                    mxi2=j;
                }

            }
        }
        if (mxi1!=0 && mxi2!=0)
        {
            c[mxi1]--;
            d[mxi2]--;
            d[mxi1]++;
            c[mxi2]++;
            ans++;
        }
    }
    cout<<ans;
    return 0;
}

#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ll long long
#define mod 1e9+7

using namespace std;

int a[10],b[10];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,i,t;
    cin>>n;
    for(i=1;i<=n;i++){
        cin>>t;
        a[t]++;
    }
    for(i=1;i<=n;i++){
        cin>>t;
        b[t]++;
    }

    int c=0,flag=0,sum=0;
    for(i=1;i<=5;i++){
        if(a[i]-b[i]>0){
            if((a[i]-b[i])%2!=0){
                flag=1;
                break;
            }
            c+=a[i]-b[i];
        }
        sum+=(a[i]-b[i]);
    }

    if(sum==0 && flag==0){
        cout<<(c/2)<<endl;
    }
    else{
        cout<<"-1\n";
        return 0;
    }

    return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define rep(i, x) for (int i = 0; i < (int)(x); i++)

typedef long long LL;
typedef pair<int, int> pii;

inline int get_int() {
  int res, c, t = 1;
  while (!isdigit(c = getchar() ) ) if (c == '-') t = -1;
  for (res = c - '0'; isdigit(c = getchar() ); )
    res = res * 10 + c - '0';
  return res * t;
}

const int MAXN = 100;

int n;
int A[10], B[10];
int del;

int main() {

  n = get_int();
  rep (i, n) {
    int c = get_int();
    A[c]++;
    del += c;
  }
  rep (i, n) {
    int c = get_int();
    B[c]++;
    del -= c;
  }

  if (del == 0) cout << 0 << endl;
  else {
    int up = 0;
    int down = 0;
    for (int i = 1; i <= 5; i++) {
      if ((A[i] + B[i]) % 2 == 1) {
        cout << -1 << endl;
        return 0;
      }
      if (A[i] > B[i]) {
        up += abs(A[i] - B[i]) / 2;
      } else {
        down += abs(B[i] - A[i]) / 2;
      }
    }
    if (up != down) cout << -1 << endl;
    else {
      cout << abs(up) << endl;
    }
    // cout << (ans) / 2 << endl;
  }

  return 0;
}

#include<iostream>
#include<map>
#include<set>
#include<algorithm>
#include<memory.h>
#include<vector>
#include<stdio.h>
#define so(v) sort(v.begin(),v.end())
typedef long long ll;
const int N=1e6;
using namespace std;
int freq[6];
int need[6];
int f1[6];
int f2[6];
int main(){
	int n;
	cin>>n;
	vector<int>a,b;
	for(int i =0 ; i < n ;i++ )
	{
		int x;
		cin>>x;
		++freq[x];
		++f1[x];
	//	a.push_back(x);
	//	b.push_back(x);
	}
	for(int i =0 ; i < n ;i++ )
	{
		int x;
		cin>>x;
		++freq[x];
		++f2[x];
	}
	set<int>st;
	int ans=0;
	bool c=0;
	for(int i =1;i<=5;++i)
		if(freq[i])
		ans=freq[i]/2,c= c || (freq[i]%2);
	if(c)
		return cout<<-1,0;
	for(int i=1;i<=5;++i)
		if(freq[i])
			need[i]=ans;
	int r=0;
	int res=0;
	for(int i =1 ; i <= 5 ; ++i)
		if(freq[i] ){
	//	if(need[i]<f1[i])
			res+=abs(f1[i]-need[i]);
		//else if(need[i]>f1[i])

		}

		cout<<res/2<<endl;
}

//include
//------------------------------------------
#include<stdio.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main(void){
	int n;
	int a[100];
	int b[100];
	cin >> n;
	int v;
	REP(i,n){
		//cin >> a[i];
		cin >> v;
		a[v-1]++;
	}
	REP(i,n){
		cin >> v;
		b[v-1]++;
	}
	int sum=0;
	REP(i,5){
		int k = abs(a[i]-b[i]);
		if(k%2!=0){
			cout << "-1" << endl;
			return 0;
		}
		else sum += k/2;
	}
	cout << sum/2 << endl;
	return 0;
}

#include <bits/stdc++.h>
#define rep(i,l,r) for(int i=l;i<r;i++)
#define put(x) cout<<#x<<" = "<<x<<endl;
#define X first
#define Y second
#define push push_back
#define pop pop_back
#define make make_pair
using namespace std;
typedef long long num;
typedef pair<int,int> point;
const int maxn=1e5+10,M=5;

int n,ans,t[2][M],a[M],b[M];

int main()
{
    cin>>n;
    rep(i,0,n)
      {
	cin>>a[i];
	t[0][a[i]-1]++;
      }
    rep(i,0,n)
      {
	cin>>b[i];
	t[1][b[i]-1]++;
      }
    rep(i,0,M)
      {
	if((t[0][i]+t[1][i])&1)
	  {
	    cout<<"-1\n";
	    return 0;
	  }
	ans+=abs(t[0][i]-t[1][i]);
      }
    cout<<ans/4<<endl;
}

#include <iostream>

using namespace std;

int main()
{
	int n, a[6] = { 0, }, b[6] = { 0, };
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		int tmp;
		cin >> tmp;
		a[tmp]++;
	}
	for (int i = 0; i < n; i++)
	{
		int tmp;
		cin >> tmp;
		b[tmp]++;
	}
	for (int i = 1; i < 6; i++)
		b[i] = (a[i] + b[i]) / 2;
	int num = 0;
	for (int i = 1; i < 6; i++)
	{
		if (a[i] > b[i])
			num += a[i] - b[i];
		else
			num += b[i] - a[i];
	}
	if (num < 2)
		cout << -1 << endl;
	else
		cout << num/2 << endl;
	return 0;
}

#include<bits/stdc++.h>
#define int long long int
using namespace std;
main(){ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  int n;cin>>n;
  vector<int>a(6,0),b(6,0);
  for(int i=0;i<n;i++){
    int x;cin>>x;
    a[x]++;
  }
  for(int i=0;i<n;i++){
    int x;cin>>x;
    b[x]++;
  }
  int ans=0;
  for(int i=1;i<=5;i++){
    ans+=abs(a[i]-b[i]);
  }
   if(ans%4==0){
    cout<<ans/4;
   }
   else cout<<-1;
}

#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#include<bits/stdc++.h>
#define F first
#define S second
#define vec vector
#define ms multiset
#define pb push_back
#define pll pair<ll,ll>
#define pdd pair<ld, ld>
#define pq priority_queue
#define umap unordered_map
#define uset unordered_set
#define pii pair<int, int>
#define pnn pair<Node*, Node*>
#define uid uniform_int_distribution
#define FILE ifstream in("input.txt");ofstream out("output.txt");
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);
using namespace std;
typedef string str;
typedef long long ll;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); //uid<int> u1(5, 10); u1(rnd);

int main() {
    fast;
    int a,x; cin>>a;
    vec<int> d(a);
    for(int q=0; q<a; q++) cin>>x, x--, d[x]++;
    for(int q=0; q<a; q++) cin>>x, x--, d[x]--;
    ll o =0;
    for(int q=0; q<5; q++) if(d[q]%2) o = -2e9; else o+=abs(d[q])/2;
    cout<<(o<0 ? -1 : o/2);
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int A[n];
    int B[n];
    int Acount1=0,Acount2=0,Acount3=0,Acount4=0,Acount5=0;
    int Bcount1=0,Bcount2=0,Bcount3=0,Bcount4=0,Bcount5=0;

    for(int i=0; i<n; i++)
        cin>>A[i];
    for(int i=0; i<n; i++)
        cin>>B[i];

    for(int i=0; i<n; i++)
    {
        if(A[i]==1)
            Acount1++;
        else if(A[i]==2)
            Acount2++;
        else if(A[i]==3)
            Acount3++;
        else if(A[i]==4)
            Acount4++;
        else if(A[i]==5)
            Acount5++;
    }
    for(int i=0; i<n; i++)
    {
        if(B[i]==1)
            Bcount1++;
        else if(B[i]==2)
            Bcount2++;
        else if(B[i]==3)
            Acount3++;
        else if(B[i]==4)
            Acount4++;
        else if(B[i]==5)
            Bcount5++;
    }
    int sum = abs(Acount2-Bcount2)+abs(Acount1-Bcount1)+abs(Acount3-Bcount3)+abs(Acount4-Bcount4)+abs(Acount5-Bcount5);
        sum=sum/2;
      int  result = sum/2;
        if((Acount1+Bcount1)%2!=0||(Acount3+Bcount3)%2!=0||(Acount2+Bcount2)%2!=0||(Acount4+Bcount4)%2!=0||(Acount5+Bcount5)%2!=0)
            result=-1;
        cout<<result<<endl;
}

////////////////////////    W H I T E C L O U D    ////////////////////////
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
ll cnt[6],cnt1[6];
int main()
{
    FAST();
    ll n,i,ans=0;
    cin>>n;
    bool test=true;
    ll a;
    for(i=1; i<=n; i++)
    {
        cin>>a;
        cnt[a]++;
        cnt1[a]++;
    }
    for(i=1; i<=n; i++)
    {
        cin>>a;
        cnt[a]++;
    }
    for(i=1; i<=5; i++)
    {
        if(cnt[i]%2!=0)
        {
            test=false;break;
        }
        else
        {
            ans+=abs(cnt[i]/2-cnt1[i]);
        }
    }
    if(test)cout<<ans<<endl;
    else cout<<"-1"<<endl;

    return 0;
}

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
int cnt[10],n,in;
int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&in);
		cnt[in]++;
	}
	for(int i=0;i<n;i++){
		scanf("%d",&in);
		cnt[in]--;
	}
	int res=0;
	for(int i=1;i<=5;i++){
		if(cnt[i]&1){
			res=-1;break;
		}
		res+=abs(cnt[i])/2;
	}
	printf("%d\n",res);
	return 0;
}

#include <iostream>
#include <math.h>
using namespace std;
int H[6];
main(){
	int n;
	cin >> n;
	int a;
	for(int i=0;i<n;i++){
		cin >> a;
		H[a]++;
	}
	for(int i=0;i<n;i++){
		cin >> a;
		H[a]--;
	}
	int s;
	for(int i=1;i<=5;i++){
		if(H[i]%2) {
			cout << -1;
			return 0;
		}
		s+= abs(H[i]);
	}
	if(s%4 == 0){
		cout << s/4;
	}	else	{
		cout << -1;
	}
}

#include <cstdio>
#include <iostream>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <cmath>
#include <cstdlib>
#include <locale>
#include <map>
#include <functional>
#include <utility>
using namespace std;
#define MS0(I) memset(I, 0, sizeof(I));
#define MS1(I) memset(I, -1, sizeof(I));
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, s, n) for(int i = (s); i < (n); ++i)
#define pb push_back
#define ALL(I) (I).begin(), (I).end()
#define MAX 105
#define F first
#define S second
typedef const void CV;
typedef long long LL;
typedef unsigned long long ULL;
int cnt[10];
int cnt2[10];
int store[MAX];
int main(void){
    int n; scanf("%d", &n);
    rep(i, n){
        scanf("%d", &store[i]);
        cnt2[ store[i]]++;
        cnt[ store[i] ]++;
    }
    rep(i, n){
        int v; scanf("%d", &v);
        cnt [v]++;
    }
    int ret = 0;
    rep1(i, 1, 6) if(cnt[i] % 2 != 0){
        puts("-1"); return 0;
    }
    rep1(i, 1, 6) ret += (cnt[i] - cnt2[i])/2;
    printf("%d", ret);
    return 0;
}

#include <cstdio>
#include <cmath>

using namespace std;

int main(){

    int n;
    scanf("%d",&n);

    int a[6]={0,},b[6]={0,};

    for(int i=0,t;i<n;i++){
        scanf("%d",&t);
        a[t]++;
    }
    for(int i=0,t;i<n;i++){
        scanf("%d",&t);
        b[t]++;
    }

    int A=0;

    for(int i=1;i<=5;i++){
        if((a[i]-b[i])%2){
            printf("-1");
            return 0;
        }
        A += abs(a[i]-b[i])/2;
    }
    printf("%d", A/2==0?-1:A/2);

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR(i,a,b) for(i= a ; i < b ; ++i)
#define rep(i,n) FOR(i,0,n)
#define INF INT_MAX
#define pb push_back
#define tc int t;cin>>t;while(t--)
#define mod (int)(1e9 + 7)
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
int main()
{
    fastio;
    int n,i,c=0,f[6]={0},sum=0;
    cin>>n;
    int a[n],b[n];
    rep(i,n)
    {
        cin>>a[i];
        f[a[i]]++;
    }
    rep(i,n)
    {
        cin>>b[i];
        f[b[i]]--;
    }
    rep(i,6)
    {
        if(f[i]%2==1)
        {
            c=1;
            break;
        }
    }
    if(c==1)
    cout<<-1<<endl;
    else
    {
        rep(i,6)
        sum+=abs(f[i]);
        cout<<sum/4<<endl;
    }

    return 0;
}

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
int a1[105];
int a2[105];
int vis1[10];
int vis2[10];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a1[i]);
        vis1[a1[i]]++;
    }
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a2[i]);
        vis2[a2[i]]++;
    }
    int ans=0;
    int ans2=0;
    int h1=0;
    int flag=0;
    for(int i=0;i<6;i++)
    {
        if(vis1[i]!=vis2[i])
        {
            ans+=vis1[i]-vis2[i];
            if(vis1[i]>vis2[i])
                ans2+=vis1[i]-vis2[i];
            if(ans2%2!=0)
                flag=1;
        }
    }
    if(flag==0||ans!=0||ans2%2!=0)
        printf("-1\n");
    else
    {
        printf("%d\n",ans2/2);
    }
    return 0;
}

#include <iostream>
#include <stdio.h>
#include <stdlib.h>

using namespace std;

int main(){
	int N, temp = 0, temp1 = 0, sum = 0, sum1 = 0, kol = 0, kol1 = 0;
	cin >> N;
	int *mass = new int [N];
	int *arr = new int [N];
	for(int i = 0; i < N; i++){
		cin >> mass[i];
	}
	for(int i = 0; i < N; i++){
		cin >> arr[i];
	}
	for(int i = 1; i < 6; i++){
		temp = 0;
		temp1 = 0;
		for(int j = 0; j < N; j++){
			if(i == mass[j]) temp++;
			if(i == arr[j]) temp1++;
		}
		sum += temp/2;
		sum1 += temp1/2;
		for(int j = 0; j < temp+temp1; j++){
			if(j%2 == 0) kol += i;
			else kol1 += i;
		}
	}
	if(sum == sum1 && kol == kol1){
		cout << sum << endl;
	}
	else {
		sum = -1;
		cout << sum << endl;
	}
	return 0;
}

#include<iostream>
#include<cmath>
using namespace std;

int hasil(int jum[]){
    int sum=0;
    for(int i=1;i<6;i++){
        if(jum[i]%2==1){
            return -1;
        }
        sum+=jum[i];
    }
    return (abs(sum/2));
}

int main(){
    int n;
    int m;
    int jum[5];
    cin>>n;
    for(int i=0;i<2;i++){
        for(int j=0;j<n;j++){
            cin>>m;
            jum[m]++;
        }
    }
    cout<<hasil(jum);
}

#include <bits/stdc++.h>
#define LL long long
#define Accel ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define Re(a,b) memset(a,b,sizeof a)
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define ALL(X) (X).begin(), (X).end()
#define FOR(I, A, B) for (int I = (A); I <= (B); I++)
#define REP(I, N) for (int I = 0; I < (N); I++)
#define PII pair<int,int>
#define PLL pair<LL,LL>
#define SZ(a) ((int)a.size())
#define endl "\n"
//#pragma GCC optimize(2)
using namespace std;
const int N=1e5+1;
const int M=1e9+7;
const double eps=1e-6;
typedef complex<double>C;
const double PI(acos(-1.0));
//__gcd, atan2(y,x)=y/x , __int128
//c(n,k)=c(n-1,k-1)+c(n-1,k)
//c(i,r),i for r to n =c(n+1,r+1)
//void add(int x){while(x<N)BIT[x]++,x+=x&-x;}
//int sum(int x){return x?BIT[x]+sum(x-(x&-x)):0;}
//int find(int x){return x==p[x]?x:p[x]=find(p[x]);}
//LL pw(LL a,LL b){LL t=1;for(;b;b>>=1,a=a*a%M)b&1?t=t*a%M:0;return t;}
//log() = ln() , log(x)/log(y)=log(y)-base-x
//INT_MAX 127,INT_MIN 128
//int dw[4][2]={{0,1},{1,0},{0,-1},{-1,0}};
//int dw[8][2]={{0,1},{1,0},{0,-1},{-1,0},{1,1},{1,-1},{-1,1},{-1,-1}};
int n;
int a[6],b[6];
int A,B;
int main(){Accel
	cin>>n;
	int x;
	FOR(i,1,n){
		cin>>x;
		a[x]++;
	}
	FOR(i,1,n){
		cin>>x;
		b[x]++;
	}
	int t=0;
	for(int i=1;i<=5;i++){
		if(a[i]&1||b[i]&1){
			cout<<-1;return 0;
		}
		t+=abs((a[i]+b[i])/2-a[i]);
	}
	//cout<<t<<endl;
	cout<<t/2<<endl;

}

//
//  main.cpp
//  Game_Of_CC
//
//  Created by Utilisateur on 05/03/17.
//  Copyright (c) 2017 Utilisateur. All rights reserved.
//

#include <iostream>
#include <cmath>
using namespace std;
long s=0;
double changes =0;

int main(int argc, const char * argv[])
{
    //cout << "he"<< endl;
    long n;
    cin >> n;
    int A[n];
    int countA[5] = {0};
    int B[n];
    int countB[5]={0};
    for (long j=0; j<n; j++) {
        cin >> A[j];
        countA[A[j]]++;
    }

    for (long j=0; j<n; j++) {
        cin >> B[j];
        countB[B[j]]++;
    }

    //cout << changes << endl;
    for (int i=1; i<6; i++) {
        s+=(countA[i]-countB[i])%2;
        changes += abs(countA[i]-countB[i])/2.0;
        //cout << abs(countA[i]-countB[i])/2.0 << endl;
    }
    if (s>0) {
        cout << -1 << endl;
    }
    else
        cout << changes << endl;

    return 0;
}

#include <iostream>
#include <vector>
using namespace std;

int main()
{
	vector <int> a;
	vector <int> b;
	int n;
	cin >> n;
	for(int i = 0; i < n; i++)
	{
		int k;
		cin >> k;
		a.push_back(k);
	}

	for(int i = 0; i < n; i++)
	{
		int k;
		cin >> k;
		b.push_back(k);
	}
	int CountA = 0;
	int CountB = 0;
	int k = 1;
	int i = 0;
	vector <int> c;
	int check = 0;

	while( k <= 5)
	{
		CountA = 0;
		CountB = 0;
		i = 0;
		while( i < n)
		{
			if(a[i] == k)
			{
				CountA++;

 			}
			if(b[i] == k)
			{
				CountB++;

			}
			i++;
		}
		k++;
		if(CountA > 0 || CountB > 0  )
		{
			c.push_back(CountA - CountB);
			if(CountA == 1 && CountB == 0 || CountB == 1 && CountA == 0)
			{
				check++;
			}
		}
	}

	int s2 = 0;
	for(int j = 0; j < c.size(); j++)
	{
		s2 += abs(c[j]);
	}
	if(check >= (float)n/2 )
	{
		cout << - 1;

		return 0;
	}
	if( s2 >= 0)
	{
		s2 /= 4;
		cout << s2;
	}

	return 0;
}

#include<bits/stdc++.h>
using namespace std;
const int maxn=200;
int a[maxn],b[maxn];
map<int,int>p,q;

int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        q[a[i]]++;

    }
    for(int i=1;i<=n;i++)
    {
        cin>>b[i];
        p[b[i]]++;
    }
    int ans=0;
    for(int i=1;i<=5;i++)
    {
        if((p[i]+q[i])%2)
        {
            cout<<"-1"<<endl;
            return 0;
        }
        else
            ans+=abs(p[i]-q[i])/2;
    }
    cout<<ans<<endl;
    return 0;
}

#include <iostream>
#include <cstdlib>

using namespace std;

int main()
{
	int n,p,q,count=0,flag=0,ans=0,temp;
	cin >> n;
	int *a=(int*)calloc(6,sizeof(int));
	int *b=(int*)calloc(6,sizeof(int));

	for(int i=1;i<=n;i++)
	{
		cin >> p;
		a[p]++;
	}
	for(int i=1;i<=n;i++)
	{
		cin >> q;
		b[q]++;
	}

	for(int j=1;j<=5;j++)
	{
		if(a[j]!=b[j])
			count++;
		if((a[j]+b[j])%2!=0)
			flag=1;
		if(a[j]==b[j])
			a[j]=b[j]=0;
		else if(a[j]>b[j])
		{
			a[j]-=b[j];
			b[j]=0;
		}
		else if(a[j]<b[j])
		{
			b[j]-=a[j];
			a[j]=0;
		}
	}

	if(flag==1)
		cout << "-1" << endl;
	else
	{
		for(int i=1;i<=5;i++)
		{
			for(int j=1;j<=5;j++)
			{
				if(b[j])
				{
					if(a[i]==b[j])
					{
						temp=a[i]-((a[i]+b[i])/2);
						if(temp<0)
							temp=-1*temp;
						ans+=temp;
						b[i]=0;
						b[j]=0;
					}
				}
			}
		}

		cout << ans << endl;
	}

}

#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,count=0;
cin>>n;
///else{if(n==1)cout<<-1<<endl;

vector<int>v1;
vector<int>v2;
for(int i=0; i<n; i++){
    int t;
    cin>>t;
    v1.push_back(t);
}
for(int i=0; i<n; i++){
    int t;
    cin>>t;
    v2.push_back(t);
}
if(n==1)cout<<-1<<endl;
else{

///for 1
   {

    int counta1=0,countb1=0;
    for(int i=0; i<n; i++){
           if(v1[i]==1)counta1++;}
    for(int i=0; i<n; i++){
           if(v2[i]==1)countb1++;}
    if(counta1>countb1)count=count-(counta1-countb1)/2;
    if(counta1<countb1)count=count+(counta1-countb1)/2;
    else count=count;
    ///cout<<count;
    }

  ///for 2
   {

    int counta1=0,countb1=0;
    for(int i=0; i<n; i++){
           if(v1[i]==2)counta1++;}
    for(int i=0; i<n; i++){
           if(v2[i]==2)countb1++;}
    if(counta1>countb1)count=count-(counta1-countb1)/2;
    if(counta1<countb1)count=count+(counta1-countb1)/2;
    else count=count;
    ///cout<<count;
    }
    ///for 3
   {

    int counta1=0,countb1=0;
    for(int i=0; i<n; i++){
           if(v1[i]==3)counta1++;}
    for(int i=0; i<n; i++){
           if(v2[i]==3)countb1++;}
    if(counta1>countb1)count=count-(counta1-countb1)/2;
    if(counta1<countb1)count=count+(counta1-countb1)/2;
    else count=count;

    }
      ///for 4
   {

    int counta1=0,countb1=0;
    for(int i=0; i<n; i++){
           if(v1[i]==4)counta1++;}
    for(int i=0; i<n; i++){
           if(v2[i]==4)countb1++;}
    if(counta1>countb1)count=count-(counta1-countb1)/2;
    if(counta1<countb1)count=count+(counta1-countb1)/2;
    else count=count;

    }
    ///for 5
   {

    int counta1=0,countb1=0;
    for(int i=0; i<n; i++){
           if(v1[i]==5)counta1++;}
    for(int i=0; i<n; i++){
           if(v2[i]==5)countb1++;}
    if(counta1>countb1)count=count-(counta1-countb1)/2;
    if(counta1<countb1)count=count+(counta1-countb1)/2;
    else count=count;

    }

  cout<<count/(-2)<<endl;
}

  return 0;
}

#include<bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin >> n;
    int a[n],b[n],arr[6]={0},brr[6]={0};
    for(int i=0;i<n;i++)
    {
        cin >> a[i];
        arr[a[i]]++;
    }
    for(int i=0;i<n;i++)
    {
        cin >> b[i];
        brr[b[i]]++;
    }
    int k=0;
    for(int i=1;i<=n;i++)
    {
        if(arr[i]+brr[i]==1)
        {
            k=1;
            break;
        }
    }
    int cnt=0;
    if(k!=1){
    int one=(arr[1]+brr[1])/2,two=(arr[2]+brr[2])/2,three=(arr[3]+brr[3])/2,four=(arr[4]+brr[4])/2,five=(arr[5]+brr[5])/2,cnt=0;
    if(one-arr[1]>0)
        cnt+=one-arr[1];
    if(one-brr[1]>0)
        cnt+=one-brr[1];
    if(two-arr[2]>0)
        cnt+=two-arr[2];
    if(two-brr[2]>0)
        cnt+=two-brr[2];
    if(three-arr[3]>0)
        cnt+=three-arr[3];
    if(three-brr[3]>0)
        cnt+=three-brr[3];
    if(four-arr[4]>0)
        cnt+=four-arr[4];
    if(four-brr[4]>0)
        cnt+=four-brr[4];
    if(five-arr[5]>0)
        cnt+=five-arr[5];
    if(five-brr[5]>0)
        cnt+=five-brr[5];
    }
    cnt/=2;
    if(k==1 && n==1)
        cout << -1;
    else
        cout << cnt;
}

#include<iostream>
#include<math.h>
#include<algorithm>
using namespace std;
int main()
{
	int n,flag=1,sum=0;
	cin>>n;
	int a[n],b[n],h1[5]={0},h2[5]={0};
	for(int i=1;i<=n;i++)
	{
	cin>>a[i];h1[a[i]]++;}
	for(int i=1;i<=n;i++)
{
	cin>>b[i] ; h2[b[i]]++;}
	for(int i=1;i<=5;i++)
	{
		if((h1[i]+h2[i])%2!=0)
		flag=0;
	}
	if(flag==0)
	{
	cout<<"-1";
	return 0;
}sum=0;
for(int i=1;i<=5;i++)
{int c=(h1[i]+h2[i])/2;
sum+=abs(c-h1[i]);
}
cout<<sum/2<<endl;
}

#include<bits/stdc++.h>

using namespace std;

inline int getint()
{
	int res=0,fh=1;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-')fh=-1,ch=getchar();
	while(ch<='9'&&ch>='0')res=res*10+ch-'0',ch=getchar();
	return res*fh;
}

int n,ans;
int a[100001],b[100001];
int cnt[100001],cnta[100001],cntb[100001];
int main()
{
	n=getint();
	for (int i=1;i<=n;i++)
	{
		cin>>a[i];
		cnta[a[i]]++;
	}
	for (int i=1;i<=n;i++)
	{
		cin>>b[i];
		cntb[b[i]]++;
	}
	int w=0,flag=0;
	for (int i=1;i<=5;i++)
	{
		w+=abs(cntb[i]-cnta[i]);
		if(cnta[i]&&cntb[i]&&abs(cntb[i]-cnta[i])!=1)flag=1;
	}
	if (w%4||!flag) cout<<-1;
	else cout<<w/4;
	return 0;
}

#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define SZ size
using namespace std;
int i,j,k,h,n,m,q,l,a[101],b[101],f[6];
int main()
{
 cin>>n;
 for(i=1;i<=n;i++)
  cin>>a[i],f[a[i]]++;
 for(i=1;i<=n;i++)
  cin>>b[i],f[b[i]]--;
 for(i=1;i<=5;i++)
  f[i]=abs(f[i]);
 for(i=1;i<=5;i++)
  if(f[i]%2==1) { cout<<-1<<endl; return 0; } else { l+=f[i]; }
 cout<<l/2<<endl;
}

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;

int a[101],b[101];
int main()
{
	int n,maxn=0;
	scanf("%d",&n);

	for(int j=1;j<=2;j++)
		for(int i=1;i<=n;i++)
		{
			int h;
			scanf("%d",&h);maxn=max(maxn,h);
			if(j==1) a[h]++;
			else b[h]++;
		}
	if(n==1)
	{
		puts("-1");
		return 0;
	}
	int ans1=0,ans2=0;
	for(int i=1;i<=maxn;i++)
	{
		if(a[i]>b[i]) ans1+=a[i]-b[i];
		else ans2+=b[i]-a[i];
	}
	if(ans1!=ans2||ans1==0)
	{
		puts("-1");
		return 0;
	}
	cout<<ans1/2;
	return 0;
}

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <queue>
#include <iomanip>
#include <cstdio>
#include <limits>
#include <cmath>
#include <cstdlib>
#include <string.h>
#include <ctime>
#include <assert.h>

using namespace std;

#define VI vector<int>
#define VVI vector<VI >
#define VB vector<bool>
#define VVB vector<VB >
#define VS vector<string>
#define PII pair<int, int>
#define VPII vector<pair<int, int> >
#define REP(var, startFrom, endTo) for(int var = startFrom; var < (int)endTo; ++var)

template <typename T>
inline const T MAX(T a, T b) { return ((a) > (b) ? (a) : (b)); }
template <typename T>
inline const T MIN(T a, T b) { return ((a) > (b) ? (b) : (a)); }
template <typename T>
inline const T ABS(T a) { return (((a) > 0) ? (a) : (-(a))); }

int n;
int solve(VI& scoresA, VI& scoresB)
{
	int ansA = 0, ansB = 0;
	int oddA = 0, oddB = 0;
	for (int i = 1; i <= 5; ++i)
	{
		int sum = scoresA[i] + scoresB[i];
		if (sum & 1)
			return -1;

		if (scoresA[i] & 1)
			++oddA;
		else
			ansA += scoresA[i] / 2;

		if (scoresB[i] & 1)
			++oddB;
		else
			ansB += scoresB[i] / 2;
	}

	if (oddA & 1)
		++oddA;
	if (oddB & 1)
		++oddB;
	oddA /= 2; oddB /= 2;

	return MIN(ansA + oddA, ansB + oddB);
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
#ifndef ONLINE_JUDGE
	freopen("tmp.in", "r", stdin);
	//	freopen("tmp.out", "w", stderr);
#endif
	cin >> n;
	VI scoresA, scoresB;
	scoresA = scoresB = VI(6);
	REP(i, 0, n)
	{
		int score;
		cin >> score;

		++scoresA[score];

	}
	REP(i, 0, n)
	{
		int score;
		cin >> score;

		++scoresB[score];
	}

	cout << solve(scoresA, scoresB) << endl;

	return 0;
}

#include<iostream>
#include<set>
using namespace std;

int main()
{

int n,i,c=0;

cin>>n;
int a[n],b[n];

for(i=0;i<n;i++)
{
cin>>a[i];
}

for(i=0;i<n;i++)
{
cin>>b[i];
}

for(i=0;i<n;i++)
{
if(a[i]!=b[i])
c++;
}

if(c%2==1)
cout<<-1;
else
cout<<c/2;

return 0;
}

#include <bits/stdc++.h>
using namespace std;

const int N = 100;
int cnt1[N+1];
int cnt2[N+1];

int main()
{
    int n; cin >> n;
    for(int i=0; i<n; ++i)
    {
        int a; cin >> a;
        ++cnt1[a];
    }
    for(int i=0; i<n; ++i)
    {
        int a; cin >> a;
        ++cnt2[a];
    }
    for(int i=1; i<=5; ++i)
    {
        if((cnt1[i]+cnt2[i])%2==1)
        {
            cout << -1;
            return 0;
        }
    }
    int cnt = 0;
    for(int i=1; i<=5; ++i)
        cnt += ((abs(cnt1[i]+cnt2[i]))/2);
    cout << cnt/2;
}

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

int A[100], B[100], AC[6], BC[6];
using namespace std;
int main(){
    int n, ans = 0;
    cin >> n;
    for(int i = 0 ; i < n ; i++){
    	cin >> A[i];
    }
    for(int i = 0 ; i < n ; i++){
    	cin >> B[i];
    }
    for(int i = 1 ; i <= 5; i++){
    	AC[i] += count(A, A+n, i);
    	BC[i] += count(B, B+n, i);
    }
    int switching = 0;
    for(int i = 1 ; i <= 5; i++){
    	if((AC[i] + BC[i]) % 2 != 0){
    		cout << -1;
    		return 0;
    	}else{
    		if(AC[i] != BC[i]){
    			int val = max(AC[i], BC[i]) - ((AC[i] + BC[i]) / 2);

    			if(switching >= val){
    				switching -= val;
    				val = 0;
    			}else{
    				val -= switching;
    				switching = 0;
    			}
    			switching += val;
    			ans += val;
    		}
    	}
    }
    cout << ans;
}

#include <iostream>
#include <math.h>
#include <stdio.h>      /* printf */
#include <stdlib.h>
using namespace std;

int main()
{
 int groupA[5]={0,0,0,0,0};
 int groupB[5]={0,0,0,0,0};
 int n;
 cin>>n;
int m=0;
int arr[5];
int sum=0;
 for(int i=0;i<n;i++){
    int x;
    cin>>x;
    x--;
    groupA[x]++;
 }for(int i=0;i<n;i++){
    int x;
    cin>>x;
    x--;
    groupB[x]++;
 }
 for(int i=0;i<5;i++){
    if((groupA[i]-groupB[i])%2==0 &&(groupA[i]-groupB[i])!=0){
       arr[i]=abs(groupA[i]-groupB[i]);
       sum+=arr[i];

    }
 }
 if(sum%2==0 &&sum!=0 &&sum/4!=0){
    cout<<sum/4;

 }
 else{cout<<"-1";}
    return 0;
}

// 4/7/2020 3:03:08 PM
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define forn(i,a,b)        for( i = a ; i < b  ; i++ )
#define debug(x)           cout << #x << " " << x << " -- \n"
#define I__O               ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define ll                 long long
#define MOD                998244353
#define pi                 pair<int,int>
#define vi                 vector <int>
#define pb                 push_back
#define vp                 vector <pair<ll,ll>>
#define endl               cout << "\n"
#define f1                 first
#define s1                 second
#define in                 insert
#define all(x)             (x).begin(),(x).end()
using namespace std ;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,
rb_tree_tag,tree_order_statistics_node_update> indexed_set ;
const int N = 2e5+13;
int tests() {
  int n ;
  cin >> n ;
  int i,x;
  int a[6][2] = {0} ;
  vector <int> v1(n),v2(n);
  forn(i,0,n)
  {
    cin >> x ;
    v1[i] = x ;
    a[x][0]++ ;
  }

  forn(i,0,n)
  {
    cin >> x ;
    v2[i] = x ;
    a[x][1]++ ;
  }
  vector <int> res(6,0);
  int ans  = 0;
  forn(i,1,6)
    if((a[i][0]+a[i][1])&1)
      return cout << -1 << '\n',0;
    else{
      int avg = a[i][0]+a[i][1] ;
      avg >>= 1 ;
      res[i] = avg;
    }
  vector <int> till(6,0);
  forn(i,0,n)
  {
    till[v1[i]]++ ;
    if(till[v1[i]] > res[v1[i]]){
      swap(v1[i],v2[i]);
      till[v2[i]] -= 1 ;
      till[v1[i]] += 1 ;
      ans++ ;
    }
  }
  bool ok =  true ;

  for(auto &t : till)
    t = 0 ;

  forn(i,0,n)
    till[v1[i]]++ ;
  forn(i,1,6)
    ok &= till[i] == res[i];

    for(auto &t : till)
    t = 0 ;

  forn(i,0,n)
    till[v2[i]]++ ;
  forn(i,1,6)
    ok &= till[i] == res[i];
  if(!ok)
    return cout << -1 << '\n',0;
  cout << ans  << '\n' ;
  return 0;
}
int main(){
    I__O ;
    int cases = 1 ;
    // cin >> cases ;
    for(int  _ = 1 ; _ <= cases ; _++ ){
    // cout << "Case #" << _ << ": ";
      tests();
    }
    return 0 ;
}

// -Wall -Weptra -O2
// -pedantic -std=c++11
// -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC

#include <bits/stdc++.h>
using namespace std;
int n,a[6],b[6],s;
int main()
{
    cin>>n;
    for(int i=1;i<=n;++i)
    {int k;
        cin>>k;
        a[k]++;
    }
      for(int i=1;i<=n;++i)
    {int k;
        cin>>k;
        b[k]++;
    }//fffff

     for(int i=1;i<=5;++i) {a[i]-=b[i];s+=abs(a[i]);}
     if(s%4!=0) cout<<-1;else cout<<s/4;
    return 0;
}

#include<iostream>
#include<algorithm>

using namespace std;
int main(){
    int n,ar[103],ar1[102],ar2[102],num1=0,num2=0,sum=0;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>ar[i];
        ar2[i]=ar[i];
    }
     for(int i=0;i<n;i++)cin>>ar1[i];

    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++)
            if(ar[j]!=0 && ar2[i]==ar[j]){num1++; ar[j]=0; }

        for(int j=0;j<n;j++)
            if(ar1[j]!=0 && ar2[i]==ar1[j]){num2++; ar1[j]=0; }

       // cout<<num1<<" "<<num2<<" "<<endl;
        if(num1>num2){
            if(abs(num1-num2)%2==0){
            sum=sum+(abs(num1-num2))/2;
            }
            else {  cout << -1 << endl; return 0;}
        }

        num1=0;
        num2=0;
    }
    cout<<sum;

return 0;
}

#include<bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin >> n;
    int a[n],b[n],arr[6]={0},brr[6]={0};
    for(int i=0;i<n;i++)
    {
        cin >> a[i];
        arr[a[i]]++;
    }
    for(int i=0;i<n;i++)
    {
        cin >> b[i];
        brr[b[i]]++;
    }
    int k=0;
    for(int i=0;i<n;i++)
    {
        if(arr[i]==1)
        {
            k=1;
            break;
        }
    }
    if(k!=1)
    {
        for(int i=0;i<n;i++)
        {
            if(brr[i]==1)
            {
                k=1;
                break;
            }
        }
    }
    int one=(arr[1]+brr[1])/2,two=(arr[2]+brr[2])/2,three=(arr[3]+brr[3])/2,four=(arr[4]+brr[4])/2,five=(arr[5]+brr[5])/2,cnt=0;
    if(one-arr[1]>0)
        cnt+=one-arr[1];
    if(one-brr[1]>0)
        cnt+=one-brr[1];
    if(two-arr[2]>0)
        cnt+=two-arr[2];
    if(two-brr[2]>0)
        cnt+=two-brr[2];
    if(three-arr[3]>0)
        cnt+=three-arr[3];
    if(three-brr[3]>0)
        cnt+=three-brr[3];
    if(four-arr[4]>0)
        cnt+=four-arr[4];
    if(four-brr[4]>0)
        cnt+=four-brr[4];
    if(five-arr[5]>0)
        cnt+=five-arr[5];
    if(five-brr[5]>0)
        cnt+=five-brr[5];
    cnt/=2;
    if(k==1 && n==1)
        cout << -1;
    else
        cout << cnt;
}

#include <iostream>
#include <cstdio>
#include <bits/stdc++.h>
using namespace std;

int main()
{
    //cout << "Hello world!" << endl;
    int n;
    scanf("%d",&n);
    int a[6],b[6];
    int sum[6];
    int t;
    memset(a,0,sizeof(a));
    memset(b,0,sizeof(b));
    memset(sum,0,sizeof(sum));
    int kind=0;
    for(int i=0;i<n;i++)
    {
        scanf("%d",&t);
        if(a[t]==0)
            kind++;
        a[t]++;
        sum[t]++;
    }
    for(int i=0;i<n;i++)
    {
        scanf("%d",&t);
        b[t]++;
        sum[t]++;
    }
    int flag=0;
    for(int i=1;i<=5;i++)
    {
        if(sum[i]%2)
        {
            flag=1;
            break;
        }
        sum[i]/=2;
    }
    int ans=0;
    if(flag)
        printf("-1\n");
    else
    {
        if(kind%2==0)
        {
            for(int i=1;i<=5;i++)
            {
                if(a[i]!=0)
                {
                    ans=ans+abs(a[i]-sum[i]);break;
                }
            }
            cout<<ans<<endl;
        }
        else
        {
            for(int i=1;i<=5;i++)
        {
            if(a[i]!=0)
            {
                ans=ans+abs(a[i]-sum[i]);
            }
        }
        printf("%d\n",ans);
        }

    }

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n, count = 0; cin>>n;
	vector <int> a(n);
	vector <int> b(n);
	vector <int> fa(6);
	vector <int> fb(5);

	for(int i = 0; i < n; i++){
		cin>>a[i];
		fa[a[i]]++;
	}
	for(int i = 0; i < n; i++){
		cin>>b[i];
		fb[b[i]]++;
	}

	for(int i = 1; i < 6; i++)
	{
		if ((fa[i] + fb[i]) % 2 != 0) {cout<<"-1"; return(0);}
		count += ( max(fa[i] , fb[i]) - min(fa[i] , fb[i]) ) / 2;
	}
	cout<<count/2;

}

#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;

int n;
int a[105], b[105];
int fra[10], frb[10];

//ifstream f("nr.txt");
//#define cin f

int main()
{
    cin >> n;
    for(int i = 1; i <= n; i++)
        cin >> a[i], fra[a[i]]++;

    for(int i = 1; i <= n; i++)
        cin >> b[i], frb[b[i]]++;

    int w = n;
    int p = 0;
    bool ok = true;

    while(w > 0 && ok)
    {
        w--;
        ok = false;
        for(int i = 1; i <= 5; i++)
            for(int j = 1; j <= 5; j++)
            if(i != j && fra[i] != 0 && frb[j] != 0)
            {

                if((fra[i] > frb[i] && fra[j] < frb[j]))
                {
                    p++;
                    fra[i]--;
                    frb[i]++;
                    fra[j]++;
                    frb[j]--;
                    ok = true;
                }
                if((fra[i] < frb[i] && fra[j] > frb[j]))
                {

                    p++;
                    fra[i]++;
                    frb[i]--;
                    fra[j]--;
                    frb[j]++;
                    ok = true;
                }
            }
    }

    if(!w)
        cout << -1;
    else
        cout << p;

}

#include<bits/stdc++.h>

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define loop(b) for(ll i=0; i<b; i++)

using namespace std;

int main();
short n,v[6],v2[6],c=0,x;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    loop(n)
        cin>>x,v[x]++;
    loop(n)
        cin>>x,v2[x]++;
    loop(6)
        c+=(abs(v[i]-v2[i]))/2;
    if(c/2==0)
        cout<<-1;
    else cout<<c/2;
}

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
using namespace std;

#define pb         push_back
#define mp         make_pair
#define ll         long long
#define PI         acos(-1.0)
#define ALL(A)     ((A).begin(), (A).end())
#define vsort(v)   sort(v.begin(),v.end())
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)

int main(){
    int n;
    cin >> n;

    //a[i]:クラスAの成績iが何人いるか
    //total[i]:クラスA,Bで成績iが何人いるか
    int a[6] = {0}, b[6] = {0}, total[6] = {0};
    FOR(i, 1, n+1){
        int input;
        cin >> input;
        a[i]++;total[i]++;
    }
    FOR(i, 1, n+1){
        int input;
        cin >> input;
        b[i]++;total[i]++;
    }

    //それぞれの成績の人が偶数でないと二つのクラスに分けられない
    FOR(i, 1, n+1){
        if(total[i]%2==1){
            cout << -1 << endl;
            return 0;
        }
    }

    //分けられる場合
    //目指す値との差が2*xならx回交換すれば良い
    int ans = 0;
    FOR(i, 1, n+1){
        ans += abs(total[i] / 2 - a[i]);
    }
    ans /= 2;
    cout << ans << endl;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll arr[1000009];
ll brr[1000009];
int main()
{
    int n;
    cin>>n;
    for(int i=0; i<n; i++)
        {
            ll x;
            cin>>x;
            arr[x]++;
        }
    for(int i=0; i<n; i++)
        {
            ll x;
            cin>>x;
            brr[x]++;
        }
    if(n==1)
    {
        cout<<"-1\n";
        return 0;
    }
    int res=0;
    for(int i=1; i<=5; i++)
    {
        ll sum=abs(arr[i]-brr[i]);
        res+=sum;
        if(sum%2==1)
        {
            cout<<"-1\n";
        }
    }
    cout<<res/4<<endl;

}

#include <bits/stdc++.h>
using namespace std;

#define Pi 3.141592653589793
#define eps 1e-9
#define MAX int(1e9)
#define MIN int(-1e9)
#define SQR(n) (n*n)
#define MEM(a,val) memset(a,val,sizeof(a))
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define vii vector< vector<int> >
#define pb push_back
#define F first
#define S second
#define SS stringstream
#define all(v) ((v).begin(),(v).end())
#define FOR(i,a,b) for(int i = a; i <= b; i++)
#define FORD(i,a,b) for(int i = b; i >= a; i--)
#define ul unsigned long
#define READ freopen("input.txt", "r", stdin);
#define WRITE freopen("output.txt", "w", stdout);
#define fast_io ios_base::sync_with_stdio(false)
#ifdef _WIN32
#  define LLD "%I64d"
#else
#  define LLD "%lld"
#endif

ll mod(ll a, ll b) // calculates a%b, not remainder
{
	ll ans;
	if(b == 0)
		return -1;
	else
	{
		ans = (a<0 ? mod(((a%b)+b),b) : a%b);
	}
	return ans;
}

int main()
{
	fast_io;
	//ifstream in_file("file.in");
	//ofstream out_file("file.out");
	int n;
	cin >> n;
	int a[5]={0},b[5]={0},c;
	FOR(i,0,n-1){
		cin >> c;
		a[c-1]++;
	}
	FOR(i,0,n-1){
		cin >>c;
		b[c-1]++;
	}
	int check = 0,num = 0;
	FOR(i,0,4){
		if(b[i] != 0 && a[i] != 0 && abs(b[i]-a[i])%2 != 0)
		{
			cout << -1 << endl;
			return 0;
		}
		num+=abs(b[i]-a[i]);
	}
	if(num%4 != 0) cout << -1 << endl;
	else cout << num/4 << endl;
	return 0;
}

#include<stdio.h>
#include<string.h>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include<functional>
#include<bits/c++io.h>
#define CLR(a,b) memset((a),(b),sizeof((a)))
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1 | 1
#define MOD 100000000
using namespace std;
typedef long long  LL;
const LL  mod=1000000007;
const int INF=1e9;
const int size=1e6+10;
int a[size];
int b[size];
int vis[size];
int num[10];
int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        CLR(vis,0);
        CLR(num,0);
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
            num[a[i]]++;
        }
        int sum=0;
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&b[i]);
            num[b[i]]++;
            if(b[i]!=a[i])
            {
                vis[i]=1;
                sum++;
            }
        }
        for(int i=1;i<=5;i++)
        {
            if(num[i]%2==1)
            {
                printf("-1\n");
                return 0;
            }
        }
    printf("%d\n",sum/2);
    }
}
//int x,y;
//int arr[10];
//int brr[10];
//void extend_gcd(int a,int b)
//{
//    if(b==0)
//    {
//        x=1;
//        y=0;
//        return ;
//    }
//    extend_gcd(b,a%b);
//    int temp=x;
//     x=y;
//     y=temp-y*(a/b);
//
//}
//int leave()
//{
//    int sum=0;
//    int m=23*28*33;
//    for(int i=1;i<=3;i++)
//    {
//        int cnt=m/brr[i];
//        extend_gcd(cnt,brr[i]);
//        printf("%d %d\n",x,y);
//        sum=(sum+x*cnt*arr[i])%m;
//    }
//    sum=(sum%m+m)%m;
//    return sum;
//}
//
//int main()
//{
//    int T;
//    scanf("%d",&T);
//    int casee=0;
//    while(1)
//    {
//        int a,b,c,d;
//        scanf("%d%d%d%d",&a,&b,&c,&d);
//        if(a==-1&&b==-1&&c==-1&&d==-1)
//            break;
//        brr[1]=23,brr[2]=28,brr[3]=33;
//        arr[1]=a,arr[2]=b,arr[3]=b;
//       int ans = leave();
//       printf("%d\n",ans);
//    }
//}
//

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>

#define test freopen("a.in","r",stdin)
typedef long long ll;
using namespace std;
ll a[999];
ll b[999];
ll d;
int main()
{
	//test;
	ll n; cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> d;
		a[d]++;
	}
	for (int i = 0; i < n; i++)
	{
		cin >> d;
		a[d]--;
		a[d]=abs(a[d]);
	}
	ll sum = 0;
	for (int i = 1; i <=5; i++)
	{
		if (a[i] % 2 == 0)
			sum += (a[i] / 2);
	}
	if (sum == 0) { cout << "-1"; return 0; }
	cout << sum;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
int main()
{
    map<int,int> m1;
    map<int,int> m2;
    m1.clear();
    m2.clear();
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        int x;
        cin>>x;
        ++m1[x];
    }

    for(int i=0;i<n;i++)
    {
        int y;
        cin>>y;
        ++m2[y];
    }

    int count1=0;
    int count2=0;
int i;
     for(i=1;i<=5;i++)
     {
         if(m1[i]>m2[i])
         {
                if((m1[i]+m2[i])%2!=0)
                    break;
             count1+=(m1[i]-m2[i])/2;
         }
         else
            if(m2[i]>m1[i])
         {
             if((m1[i]+m2[i])%2!=0)
                    break;
             count2+=(m2[i]-m1[i])/2;
         }
     }
        if(count1==count2&&count1!=0)
            cout<<count1<<endl;
        else
            if(i<=5||(count1!=count2))
            cout<<-1<<endl;
    }

#include<iostream>
#include<math.h>
using namespace std;

int main(){
    int n;
    cin>>n;
    int g1[n],g2[n],freq[6],out=0;
    for(int i=0;i<n;i++)cin>>g1[i];
    for(int i=0;i<n;i++)cin>>g2[i];
    for(int i=0;i<n;i++){
        freq[g1[i]]++;
        freq[g2[i]]--;
    }
    for(int i=0;i<n;i++){
        if(g1[i]&1||g2[i]&1){
            cout<<-1;
            return 0;
        }
    }
    for(int i=0;i<n;i++){
        out+=(freq[i]>0? freq[i]:-freq[i]);
    }
    cout<<out;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n;
    cin>>n;
    ll a[n],b[n];
    map<ll,ll>a1;
    map<ll,ll>b1;
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        a1[a[i]]++;
    }
    for(ll i=0;i<n;i++)
    {
        cin>>b[i];
        b1[b[i]]++;
    }
    ll count=0;
    for(ll i=1;i<=5;i++)
    {
        count+=abs(a1[i]-b1[i])/2;
    }
    count=count/2;
    if(count==0)
        cout<<"-1\n";
    else
    cout<<count<<"\n";
    return 0;
}

#include<bits/stdc++.h>
#include<math.h>
using namespace std;
int a[7],b[7];
int main()
{
    int n;
    cin>>n;

    int x,y,ans=0,t;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        a[x]++;

    }
    for(int i=0;i<n;i++)
    {
        cin>>y;
        b[y]++;
    }
    for(int i=1;i<=6;i++)
    {
        //cout<<a[i]<<" "<<b[i]<<endl;
        if(a[i]>1)
        {
            t=abs(a[i]-b[i]);
            t/=2;
            ans+=t;
        }
    }
    if(ans)
        cout<<ans<<endl;
    else cout<<-1<<endl;
}

#include <iostream>

using namespace std;

int fr1[6], fr2[6];

int main(){
    int n, i, x, y, sum;
    cin>>n;
    if(n==1){
        cin>>x, cin>>y;
        if(x!=y){
            cout<<-1;
            return 0;
            }
    }
    for(i=1; i<=n; i++){
        cin>>x;
        fr1[x]++;
    }
    for(i=1; i<=n; i++){
        cin>>y;
        fr2[y]++;
    }
    sum=0;
    for(i=1; i<=5; i++){
        sum+=max(fr1[i], fr2[i])-min(fr1[i], fr2[i]);
    }
    if(sum%4!=0)
        cout<<-1;
    if(sum%4==0)
        cout<<sum/4;

        return 0;
        }

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin>>n;

    int a[6];
    for(int i=0; i<=5; i++){
        a[i]=0;
    }
    for(int i=0; i<n; i++){
        int brojce;
        cin>>brojce;
        a[brojce]++;
    }

    int b[6];
    for(int i=0; i<=5; i++){
        b[i]=0;
    }
    for(int i=0; i<n; i++){
        int brojce;
        cin>>brojce;
        b[brojce]++;
    }

//    for(int i=0; i<=5; i++){
//        cout<<a[i]<<" "<<b[i]<<endl;
//    }

    for(int i=1; i<6; i++){
        int zbir=a[i]+b[i];
        if(zbir%2==1){
            cout<<-1;
            return 0;
        }
    }
int cnt=0;
    for(int i=1; i<6; i++){
        if(a[i]<b[i]) swap(a[i], b[i]);
        cnt+=a[i]-b[i];
    }
    cout<<cnt/2;
    return 0;
}

#include <bits/stdc++.h>
#define LL long long
#define Accel ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define Re(a,b) memset(a,b,sizeof a)
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define ALL(X) (X).begin(), (X).end()
#define FOR(I, A, B) for (int I = (A); I <= (B); I++)
#define REP(I, N) for (int I = 0; I < (N); I++)
#define PII pair<int,int>
#define PLL pair<LL,LL>
#define SZ(a) ((int)a.size())
#define endl "\n"
//#pragma GCC optimize(2)
using namespace std;
const int N=1e5+1;
const int M=1e9+7;
const double eps=1e-6;
typedef complex<double>C;
const double PI(acos(-1.0));
//__gcd, atan2(y,x)=y/x , __int128
//c(n,k)=c(n-1,k-1)+c(n-1,k)
//c(i,r),i for r to n =c(n+1,r+1)
//void add(int x){while(x<N)BIT[x]++,x+=x&-x;}
//int sum(int x){return x?BIT[x]+sum(x-(x&-x)):0;}
//int find(int x){return x==p[x]?x:p[x]=find(p[x]);}
//LL pw(LL a,LL b){LL t=1;for(;b;b>>=1,a=a*a%M)b&1?t=t*a%M:0;return t;}
//log() = ln() , log(x)/log(y)=log(y)-base-x
//INT_MAX 127,INT_MIN 128
//int dw[4][2]={{0,1},{1,0},{0,-1},{-1,0}};
//int dw[8][2]={{0,1},{1,0},{0,-1},{-1,0},{1,1},{1,-1},{-1,1},{-1,-1}};
int n;
int a[6],b[6];
int A,B;
int main(){Accel
	cin>>n;
	int x;
	FOR(i,1,n){
		cin>>x;
		a[x]++;
	}
	FOR(i,1,n){
		cin>>x;
		b[x]++;
	}

	for(int i=1;i<=5;i++){
		if(a[i]>b[i])A+=a[i]-b[i];
		else B+=b[i]-a[i];
	}
	if(A>=2&&B>=2&&(A+B)%4==0)
		cout<<(A+B)/4;
	else cout<<-1;

}

#include<iostream>
#include<algorithm>
using namespace std;
int cnt[5]={0};
int main()
{
    int n;
    cin>>n;
    int arra[n+1],arrb[n+1];
    for(int i=0;i<n;i++){
        cin>>arra[i];
        cnt[arra[i]]++;
    }
    for(int i=0;i<n;i++){
        cin>>arrb[i];
        cnt[arrb[i]]++;
    }
    bool ck=true;
    for(int i=0;i<=5;i++){
        if(cnt[i]%2){
            ck=false;
            break;
        }
    }
    if(!ck) cout<<-1<<endl;
    else{
        sort(arra,arra+n);
        sort(arrb,arrb+n);
        int count=0;
        for(int i=0;i<n;i++){
            if(arra[i]!=arrb[i]) count++;
        }
        cout<<(count/2)<<endl;
    }
    return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
#include <map>
#include <set>
#include <string>
#include <fstream>
#include <queue>
using namespace std;

#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define pb push_back
#define mp make_pair
#define F first
#define S second

typedef long long ll;
typedef pair<int,int> Pii;

const ll LINF=(ll) 1e18;
const int INF=(int) 1e9+7;
const int N=(int) 1e5+1;
const double PI=3.14159265359;

bool u[N+5];
int a[5],b[5];
int main()
{ //freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	_
	int n;
	cin>>n;
	for (int i=1;i<=n;++i){
		int x;
		cin>>x;
		a[x]++;
	}
	for (int i=1;i<=n;++i){
		int x;
		cin>>x;
		b[x]++;
	}
	for (int i=1;i<=5;++i){
		if ((a[i]+b[i])%2){
			cout<<-1;
			return 0;
		}
	}
	int res=0;
	for (int i=1;i<=5;++i){
		res+=(abs(a[i]-b[i])/2);
	}
	cout<<res/2;
  return 0;
}

#include <bits/stdc++.h>
using namespace std;

typedef long long  ll;

#define oo              (1<<30)
#define MOD             1000000007
#define fin              return 0
#define F                first
#define S                second
#define all(x)           x.begin(),x.end()
#define loop(i,n)        for(int i=0;i<n;i++)
#define lop(i,n)         for(int i=1;i<=n;i++)
#define loopv(i,n)       for(int i=n-1;i>=0;i--)

ll conv_to_num(string s){
stringstream ss;
ss<<s;
ll f;
ss>>f;
return f;
}
string conv_to_string(ll s){
stringstream ss;
ss<<s;
string f;
ss>>f;
return f;
}
map<int , int>m1;
map<int , int>m2;
int mark[10000];
int main(){

    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false), cin.tie(NULL);

    int n ;
    cin >> n ;
    int a[n] , b[n];
    loop(i,n){
    cin >> a[i];
    m1[a[i]]++;
    }
    loop(i,n){
    cin >> b[i];
    m2[b[i]]++;
    }
    int ans=0;
    loop(i,n){
    int x=a[i];
    if(!mark[x]){
            int f1=m1[x];
          int f2=m2[x];
    while(1){
       if(f2==f1)break;
       else if(f2>f1){f2--;f1++;ans++;}
       else if(f1>f2){f1--;f2++;ans++;}
      if(!f1 || !f2)break;
    }
       mark[x]=1;
    }

    }
    loop(i,n){
    int x=b[i];
    if(!mark[x]){
            int f1=m1[x];
          int f2=m2[x];
    while(1){
       if(f2==f1)break;
       else if(f2>f1){f2--;f1++;ans++;}
       else if(f1>f2){f1--;f2++;ans++;}
       if(!f2 || !f1)break;

    }
       mark[x]=1;
    }

    }
   if(ans/2==0){cout<<-1;fin;}
cout << ans/2;
return 0;
}

#include <bits/stdc++.h>
#define ull                 unsigned long long
#define ll                  long long
#define vi                  vector<int>
#define v2i                 vector< vector<int> >
#define vl                  vector<long long>
#define v2l                 vector< vector<long long> >
#define ii                  pair<int, int>
#define si                  set<int>;
#define msi                 map<string, int>
#define FOR(i,a,b)          for(int i=a;i<=b;i++)
#define ahmed_elmotaz       ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const ll mod = 1000000007;
/* a=97  A=65 z=122 Z=90 0=48 */
/* for(int i=0;i<t;i++){} */
using namespace std;

int main()
{
    ahmed_elmotaz
    int t,x;cin>>t;
    vi arr1(6,0);
    vi arr2(6,0);
    FOR(i,0,t-1){
        scanf("%d",&x);
        arr1[x]++;
    }
    FOR(i,0,t-1){
        scanf("%d",&x);
        arr2[x]++;
    }
    vi arr(6,0);
    bool work=1;int ans=0;
    FOR(i,1,5){
        if(abs(arr1[i]-arr2[i])%2==1){ans=0;break;}
        else{
            int z=abs(arr1[i]-arr2[i]);
            ans+=z/2;
        }
    }
    if(ans==0){
        cout<<"-1 \n";
    }
    else{
        cout<<ans/2<<endl;
    }

    return 0;
}
/**/

#include <iostream>
#include <algorithm>
#include <string>
#include <unordered_map>
#include <set>

using namespace std;
typedef long long ll;

int main()
{
	int n;
	int a[6], b[6], diff[6];
	int d;
	cin >> n;
	int ans = 0;
	for(int i = 0; i < n; ++i) {cin >> d; a[d]++; }
	for(int i = 0; i < n; ++i) {cin >> d; b[d]++; }
	for(int i = 1; i < 6; ++i) diff[i] = a[i] - b[i];
	for(int i = 1; i <= 5; ++i)
	{
		if( (a[i] + b[i]) % 2 == 0 )
			ans += abs(diff[i]);
		else
		{
			cout << -1;
			return 0;
		}
	}
	cout << ans / 4;
	return 0;
}

#include<iostream>
#include<vector>
#include<algorithm>
#include<sstream>
#include<stdio.h>
#include<math.h>
#include<set>
using namespace std;

int main()
{
     //freopen("input.txt","r",stdin);
     //freopen("output.txt","w",stdout);
  long long cnt=0,t,a;
  long long p[100100];
  long long x,i,j,k=0,max1=0,min1,sm[5],sm1[5];
  char c;
  string b;
   vector<long long> z,y;
   vector<char> ca;
size_t s;
cin>>t;

for(i=0;i<5;i++)
{
    sm[i]=0;
    sm1[i]=0;
}
for(i=0;i<t;i++)
{
    cin>>x;
    z.push_back(x);
    sm[x-1]++;
}
for(i=0;i<t;i++)
{
    cin>>x;
    y.push_back(x);
    sm1[x-1]++;
}
/*for(i=0;i<5;i++)
{
    if(sm[i]!=sm1[i])
    {
       // e=1;
    }
    else
    {

    }

}
  */

for(i=0;i<5;i++)
{
    sm[i]=sm[i]-sm1[i];
}

for(i=0;i<5;i++)
{
    if(sm[i]%2==1)
    {
        cout<<"-1";
        break;
    }
    else
    {
        k=k+sm[i]/2;
    }
}
cout<<k<<endl;
}