// use std::ops::{Index, IndexMut};
// use std::cmp::{Ordering, min, max};
// use std::collections::{BinaryHeap, BTreeMap};
// use std::collections::btree_map::Entry::{Occupied, Vacant};
// use std::clone::Clone;

fn getline() -> String{
    let mut res = String::new();
    std::io::stdin().read_line(&mut res).ok();
    res
}

macro_rules! readl {
    ($t: ty) => {
        {
            let s = getline();
            s.trim().parse::<$t>().unwrap()
        }
    };
    ($( $t: ty),+ ) => {
        {
            let s = getline();
            let mut iter = s.trim().split(' ');
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*) 
        }
    };
}

macro_rules! readlvec {
    ($t: ty) => {
        {
            let s = getline();
            let iter = s.trim().split(' ');
            iter.map(|x| x.parse().unwrap()).collect::<Vec<$t>>()
        }
    }
}

macro_rules! mvec {
    ($v: expr, $s: expr) => {
        vec![$v; $s]
    };
    ($v: expr, $s: expr, $($t: expr),*) => {
        vec![mvec!($v, $($t),*); $s]
    };
}

macro_rules! debug {
    ($x: expr) => {
        println!("{}: {:?}", stringify!($x), $x)
    }
}

fn printiter<'a, T>(v: &'a T)
where
    &'a T: std::iter::IntoIterator, 
    <&'a T as std::iter::IntoIterator>::Item: std::fmt::Display {
    for (i,e) in v.into_iter().enumerate() {
        if i != 0 {
            print!(" ");
        }
        print!("{}", e);
    }
    println!("");
}

fn main() {
    let a: Vec<_> = readl!(String).chars().map(|a| a == '1').collect();
    let b: Vec<_> = readl!(String).chars().map(|a| a == '1').collect();
    let n = b.len();
    let mut left_one = vec![n+1; n];
    let mut x = n+1;
    
    if b.iter().filter(|&&x| x).count() == 0 {
        if a.iter().filter(|&&x| x).count() == 0 {
            println!("0");
        } else {
            println!("-1");
        }
        return;
    }

    for i in 0..2*n {
        let p = i%n;
        if b[p] {
            x = 0;
        } else {
            x += 1;
        }
        left_one[p] = x;
    }
    let left_one = left_one;

    let mut right_one = vec![n+1; n];
    let mut x = n+1;
    for i in (0..2*n).rev() {
        let p = i%n;
        if b[p] {
            x = 0;
        } else {
            x += 1;
        }
        right_one[p] = x;
    }
    let right_one = right_one;

    // debug!(left_one);
    // debug!(right_one);
    let inf = 1_000_000_00;
    let mut ans = inf;
    for d in 0..n {
        // debug!(d);
        {
            let mut vv = vec![(0, 0); n];
            let mut diff_cnt = 0;
            for i in 0..n {
                if b[(i+d)%n] !=  a[i] {
                    diff_cnt += 1;
                }
                if !b[(i+d)%n] && a[i] {
                    let left = left_one[i];
                    let right = if right_one[i] <= d {
                        0
                    } else {
                        right_one[i]-d
                    };
                    vv[i] = (left, right);
                }
            }
            // debug!(vv);
            vv.sort();
            for i in (0..n-1).rev() {
                vv[i].1 = std::cmp::max(vv[i+1].1, vv[i].1);
            }
            // debug!(vv);
            let mut val = std::cmp::min(vv[0].1, vv.last().unwrap().0);
            for i in 0..n-1 {
                val = std::cmp::min(val, vv[i+1].1+vv[i].0);
            }
            // debug!(val+d+diff_cnt);
            ans = std::cmp::min(ans, val*2+d+diff_cnt);
        }
        {
            let mut vv = vec![(0, 0); n];
            let mut diff_cnt = 0;
            for i in 0..n {
                if b[(i+d)%n] !=  a[i] {
                    diff_cnt += 1;
                }
                if !b[(i+d)%n] && a[i] {
                    let right = right_one[i];
                    let left = if left_one[i] <= n-d {
                        0
                    } else {
                        left_one[i]-(n-d)
                    };
                    vv[i] = (left, right);
                }
            }
            // debug!(vv);
            vv.sort();
            for i in (0..n-1).rev() {
                vv[i].1 = std::cmp::max(vv[i+1].1, vv[i].1);
            }
            // debug!(vv);
            let mut val = std::cmp::min(vv[0].1, vv.last().unwrap().0);
            for i in 0..n-1 {
                val = std::cmp::min(val, vv[i+1].1+vv[i].0);
            }
            // debug!(val+n-d+diff_cnt);
            // debug!(n-d);
            // debug!(diff_cnt);
            ans = std::cmp::min(ans, val*2+(n-d)+diff_cnt);
        }
    }
    println!("{}", ans);
}



Measured memory_bytes: 4476