#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  int T = 1;
  while (T--) {
    string a, b;
    cin >> a >> b;
    if (a.compare(b) == 0)
      cout << -1 << endl;
    else if (a.size() > b.size())
      cout << a.size() << endl;
    else
      cout << b.size() << endl;
  }
  return 0;
}
