#include <bits/stdc++.h>
using namespace std;
int main() {
  string a, b;
  cin >> a;
  cin >> b;
  int i, j, p, q, c = 0;
  p = a.size();
  q = b.size();
  int m = max(p, q);
  if (p > q || q > p) {
    cout << m;
    return 0;
  }
  for (i = 0; i < p; i++) {
    if (a[i] == b[i]) c++;
  }
  if (c == p)
    cout << -1;
  else
    cout << p;
}
