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

#define OUT(x)  cerr << #x << " = " << x << endl;
#define all(x)  x.begin(), x.end()
#define mp      make_pair
#define pii     pair<int, int>
#define pll     pair<long long, long long>
#define ll      long long

static const int INF = 0x3f3f3f3f;

int solve(string a, string b) {
        int n = a.size();
        int left = 0, right = 0;
        for (int i = 0; i < n; i ++) {
                if (b[i] == '0') left ++;
                else break;
        }
        for (int i = n - 1; i >= 0; i --) {
                if (b[i] == '0') right ++;
                else break;
        }
        vector<int> one;
        for (int i = 0; i < n; i ++) if (b[i] == '1') one.push_back(i);
        int op = 0;
        vector<pair<int, int>> dis(n);
        for (int i = 0; i < n; i ++) {
                if (one[op] == i) { 
                        dis[i] = mp(0, 0);
                        op ++;
                } else if (op == 0) {
                        dis[i] = mp(i + 1 + right, one[op] - i);
                } else if (op == one.size()) {
                        dis[i] = mp(i - one[op - 1], n - i + left);
                } else {
                        dis[i] = mp(i - one[op - 1], one[op] - i);
                }
        }
        int ans = INF;
        for (int shift = 0; shift <= n; shift ++) {
                int flip_cnt = 0;
                vector<bool> flip(n, false);
                for (int i = 0; i < n; i ++) {
                        if (a[i] != b[(i - shift + n) % n]) {
                                flip_cnt ++;
                                flip[i] = true;
                        }
                }
                vector<pair<int, int>> dis_modified;
                for (int i = 0; i < n; i ++) if (flip[i]) { 
                        dis_modified.emplace_back(max(dis[i].first - shift, 0), dis[i].second);
                }
                sort(all(dis_modified));
                reverse(all(dis_modified));

                //pair<int, int> x = mp(0, 0);
                //for (int i = 0; i < dis_modified.size(); i ++) {
                //        if (dis_modified[i].first <= x.first || dis_modified[i].second <= x.second) continue;
                //        if (dis_modified[i].first - x.first <= dis_modified[i].second - x.second) {
                //                x.first = dis_modified[i].first;
                //        } else {
                //                x.second = dis_modified[i].second;
                //        }
                //}

                int cur = INF;
                int ma = 0;
                for (int i = 0; i < dis_modified.size(); i ++) {
                        cur = min(cur, dis_modified[i].first + ma);
                        ma = max(ma, dis_modified[i].second);
                }
                cur = min(cur, ma);

                //cout << "shift = " << shift << endl;
                //cout << "flip_cnt = " << flip_cnt << endl;
                //for (int i = 0; i < n; i ++) cout << flip[i];
                //cout << endl;
                //cout << "(x, y) = " << x.first << ' ' << x.second << endl;
                int res = shift + flip_cnt + 2 * cur;
                //cout << "res = " << res << endl;
                ans = min(ans, res);
        }
        return ans;
}
int main() {
        string a, b;
        cin >> a >> b;
        bool no = true;
        for (int i = 0; i < b.size(); i ++) if (b[i] == '1') no = false;
        if (no) { 
                for (int i = 0; i < a.size(); i ++) if (a[i] == '1') {
                        cout << -1 << endl;
                        return 0;
                }
                cout << 0 << endl;
                return 0;
        }
        int ans = solve(a, b);
        reverse(all(a));
        reverse(all(b));
        ans = min(ans, solve(a, b));
        cout << ans << endl;
        return 0;
}


Measured memory_bytes: 384