#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, s1;
  cin >> s >> s1;
  int n = s.length();
  int m = s1.length();
  int l = max(n, m);
  if (s.length() != s1.length()) {
    cout << max(n, m);
  } else {
    for (int i = 0; i < l; i++) {
      if (s[i] != s1[i]) {
        cout << max(n, m);
        break;
      }
      if (i == (l - 1)) cout << -1;
    }
  }
}
