#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ;
  string a, b;
  cin >> a >> b;
  if (a.size() > b.size()) {
    string t = a;
    a = b;
    b = t;
  }
  for (int i = 0; i < b.size(); i++) {
    bool notfound = false;
    for (int j = 0; j < b.size(); j++) {
      if (a[i] == b[i]) {
        notfound = true;
        break;
      }
    }
    if (!notfound) {
      cout << b.size();
      return 0;
    }
  }
  cout << -1;
}
