#include <bits/stdc++.h>
using namespace std;
int main() {
  string x, y;
  int ans;
  cin >> x >> y;
  if (x.compare(y) != 0)
    ans = max(x.length(), y.length());
  else
    ans = -1;
  cout << ans;
  return 0;
}
