#include <bits/stdc++.h>
using namespace std;
long long int po[1005][10];
vector<int> primes;
using ll = long long int;
using dl = double;
int main() {
  ios_base::sync_with_stdio(false);
  string ptr, str, uni;
  ll n, i, j, p, m, after, a[100000], t, k, mark,
      c = 0, bose, daray, ans = INT_MIN, sum = 0, b[100000], s;
  set<pair<ll, ll>> cv;
  char ch[101][101];
  set<ll> sc;
  cin >> str >> ptr;
  if (str == ptr) {
    cout << -1 << endl;
    return 0;
  } else if (str.length() > ptr.length()) {
    cout << str.length() << endl;
  } else
    cout << ptr.length() << endl;
}
