#include <bits/stdc++.h>
using namespace std;
int main() {
  string s1, s2;
  cin >> s1;
  cin >> s2;
  long long flag = 0;
  long long x = s1.length();
  long long y = s2.length();
  if (x != y) {
    long long z = (x > y) ? x : y;
    cout << z;
  } else {
    for (long long i = 0; i < x; i++) {
      if (s1[i] != s2[i]) {
        flag = 1;
        break;
      }
    }
    if (flag == 1)
      cout << x;
    else
      cout << -1;
  }
}
