#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e6 + 10;
long long a[MAX];
int main() {
  int t = 1;
  while (t--) {
    string a, b;
    cin >> a >> b;
    if (a == b)
      cout << "-1" << endl;
    else
      cout << max(a.size(), b.size()) << endl;
  }
  return 0;
}
