#include <bits/stdc++.h>
using namespace std;
string name1, name2;
int main() {
  int t, n, m, k, i, j, p;
  getline(cin, name1);
  getline(cin, name2);
  t = name1.size();
  k = name2.size();
  if (name1 == name2)
    cout << -1 << endl;
  else {
    if (t >= k)
      cout << t << endl;
    else
      cout << k << endl;
  }
}
