#include <bits/stdc++.h>
#define FOR(i, n) for(int i = 0; i < (n); ++i)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define TRAV(i, a) for(auto &i : (a))
#define SZ(x) ((int)(x).size())
#define X first
#define Y second
#define MP std::make_pair
#define PR std::pair
typedef long long ll;
typedef std::pair<int, int> PII;
typedef std::vector<int> VI;

VI a, b;


int main(){
        std::ios_base::sync_with_stdio(false);
        std::cin.tie(0);

        int n;
        std::cin >> n;
        std::string x, y;
        std::cin >> x >> y;
        a.resize(n);
        b.resize(n);
        FOR(i, n) a[i] = x[i]-'0', b[i] = y[i]-'0';

        ll ans = 0;
        int need = 0;
        if(a[0] != b[0]) ans = need = 1;

        REP(i, 1, n){
                if(need > 0){
                        if(a[i] == 1){
                                a[i] = 0;
                                need--;
                        }
                }
                if(a[i] != b[i]) need++;
                ans += need;
        }

        if(need == 0) std::cout << ans << "\n";
        else std::cout << -1 << "\n";


        return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd_(ll a,ll b){if(a%b==0)return b;return gcd_(b,a%b);}
ll lcm_(ll a,ll b){ll c=gcd_(a,b);return ((a/c)*b);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
//tie(a,b,c) = make_tuple(10,9,87);
#define pop_(a) __builtin_popcount((a))
ll keta(ll a){ll r=0;while(a){a/=10;r++;}return r;}
#define num_l(a,v) POSL(a,v) //v未満の要素数
#define num_eql(a,v) POSU(a,v) //v以下の要素数
#define num_h(a,v) (a.size() - POSU(a,v)) //vより大きい要素数
#define num_eqh(a,v) (a.size() - POSL(a,v)) //v以上の要素数
// static_cast< long long ll >















int N = 30*30;
int L = 30;
// (i,j) i個下 , j個右
int ind(int a,int b){
	return a*L + b;
}

//vector< vector<string> > S(N,vector<string>(N));
vector<vector<long double>> H(L,vector<long double>(L,5000.0));
vector<vector<long double>> V(L,vector<long double>(L,5000.0));


// 上は下より(i,j)のiが小さい　右は左より(i,j)のjが大きい

// 順路正の向きで
const int From_U = 0;//上から来た
const int From_D = 1;//下から来た
const int From_L = 2;//左から来た
const int From_R = 3;//右から来た

// 復元
string make_char = "DURL";
const int dy[] = {-1,1,0,0};
const int dx[] = {0,0,-1,1};

int main(){
	int sy,sx,ty,tx;
	int s,t;
	FOR(k,0,1000){
		cin >> sy >> sx >> ty >> tx;

		int dir_y = 1;
		int dir_x = 1;
		if(sy > ty) dir_y = -1;
		if(sx > tx) dir_x = -1;

		// (i,j) には (i - dir_y , j) or (i , j - dir_x) から行く

		vector< vector<long double> > score(L,vector<long double>(L,INF));
		vector< vector<int> > from(L,vector<int>(L,-1));

		score[sy][sx] = 0;
		for(int y=sy;(y-dir_y)!=ty;y+=dir_y){
			for(int x=sx;(x-dir_x)!=tx;x+=dir_x){
				//cout << y << " " << x << endl;
				
				if(y==sy && x==sx) continue;
				long double a = INF,b = INF;
				if(y != sy) a = score[y-dir_y][x] + H[min(y-dir_y,y)][x];
				if(x != sx) b = score[y][x-dir_x] + V[y][min(x,x-dir_x)];

				if(a < b){
					from[y][x] = (dir_y == 1 ? From_U : From_D );
					score[y][x] = a;
				}else{
					from[y][x] = (dir_x == 1 ? From_L : From_R );
					score[y][x] = b;
				}

				
			}
		}
		//return 0;
		//cout << "95" << endl;

		string T;
		int y=ty,x=tx;
		while(y!=sy || x!=sx){
			int a = from[y][x];
			T += make_char[a];
			assert(0 <= a && a <= 3);
			y += dy[a];
			x += dx[a];
			//cout << "from[" << y <<  "][" << x << "] = "  << a << endl;
		} 

		//cout << "106" << endl;


		//cout << T << endl;
		REV(T);
		/*{ // チェック
			assert(T.size() == (abs(sy-ty)+abs(sx-tx)));
			int ud=0,lr=0;
			for(auto c:T){
				if(c == 'U' || c == 'D') ud++;
				if(c == 'L' || c == 'R') lr++;
			}
			assert(abs(sy-ty) == ud);
			assert(abs(sx-tx) == lr);
		}*/
		cout << T << endl;
		cout << flush;

		long double score_now,r;
		cin >> score_now;

		r = pow( score_now / score[ty][tx] , 1.0 - 1.0*(abs(sy-ty) + abs(sx-tx)) / 110.0 );

		y=ty,x=tx;
		while(y!=sy || x!=sx){
			int a = from[y][x];
			int by = y + dy[a],bx = x + dx[a];
			if(by != y){
				H[min(by,y)][x] *= r;
			}else{
				V[y][min(bx,x)] *= r;
			}
			y += dy[a];
			x += dx[a];
		}
	}
}