#include <bits/stdc++.h>
using namespace std;
string one, two;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << setprecision(20);
  cin >> one >> two;
  if (one == two) {
    cout << -1 << endl;
  } else {
    cout << max(one.size(), two.size()) << endl;
  }
  return 0;
}
