#include <bits/stdc++.h>
using namespace std;
class DSU {
 private:
  vector<int> ids;
  vector<int> h;

 public:
  DSU(int n) {
    ids.resize(n);
    h.resize(n);
    for (int i = 0; i < n; i++) {
      ids[i] = i;
      h[i] = 1;
    }
  }
  int getRoot(int ind) {
    if (ids[ind] != ind) return getRoot(ids[ind]);
    return ind;
  }
  bool connected(int ind1, int ind2) { return getRoot(ind1) == getRoot(ind2); }
  void connect(int ind1, int ind2) {
    if (connected(ind1, ind2)) return;
    int r1 = getRoot(ind1);
    int r2 = getRoot(ind2);
    if (h[r1] > h[r2]) {
      ids[r2] = r1;
      h[r1] += h[r2];
    } else {
      ids[r1] = r2;
      h[r2] += h[r1];
    }
  }
  int idCount() {
    set<int> check;
    for (auto i : ids) check.insert(i);
    return (int)check.size();
  }
};
long long gcd(long long a, long long b) {
  while (b != 0) {
    long long t = a % b;
    a = b;
    b = t;
  }
  return a;
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
int sgn(int n) {
  if (n < 0) return -1;
  if (n > 0) return 1;
  return 0;
}
int sgn(long long n) {
  if (n < 0LL) return -1;
  if (n > 0LL) return 1;
  return 0;
}
inline int nextInt() {
  int n;
  scanf("%d", &n);
  return n;
}
inline long long nextLong() {
  long long n;
  scanf("%lld", &n);
  return n;
}
inline double nextDouble() {
  double n;
  scanf("%lf", &n);
  return n;
}
inline string nextLine() {
  static char ______________buffer[1000005];
  fgets(______________buffer, 1000000, stdin);
  string res = ______________buffer;
  if (*(res.end() - 1) == '\n') res.erase(res.end() - 1);
  return res;
}
inline char nextChar() {
  char n;
  scanf("%c", &n);
  return n;
}
inline string next() {
  static char ______________buffer[1000005];
  scanf("%s", ______________buffer);
  string res = ______________buffer;
  return res;
}
string nToKss(string num, int n, int k) {
  static unordered_map<char, int> _______________________SSSSSSSSSSSSSSSSSS;
  static unordered_map<int, char> _______________________SSSSSSSSSSSSSSSSS;
  if ((int)_______________________SSSSSSSSSSSSSSSSSS.size() == 0) {
    int c = 0;
    for (char i = '0'; i <= '9'; i++) {
      _______________________SSSSSSSSSSSSSSSSSS[i] = c++;
      _______________________SSSSSSSSSSSSSSSSS[c - 1] = i;
    }
    for (char i = 'A'; i <= 'Z'; i++) {
      _______________________SSSSSSSSSSSSSSSSSS[i] = c++;
      _______________________SSSSSSSSSSSSSSSSS[c - 1] = i;
    }
    for (char i = 'a'; i <= 'z'; i++) {
      _______________________SSSSSSSSSSSSSSSSSS[i] = c++;
      _______________________SSSSSSSSSSSSSSSSS[c - 1] = i;
    }
  }
  long long f = 0;
  reverse(num.begin(), num.end());
  long long powpow = 1;
  for (auto i : num) {
    f += _______________________SSSSSSSSSSSSSSSSSS[i] * powpow;
    powpow *= n;
  }
  string res;
  while (f > 0) {
    res += _______________________SSSSSSSSSSSSSSSSS[f % k];
    f /= k;
  }
  reverse(res.begin(), res.end());
  return res;
}
long long mod = 998244353;
double const PI = 3.1415926535897932384626433832795;
int main() {
  string str1 = next();
  nextChar();
  string str2 = next();
  if (str1 == str2) return !printf("-1");
  printf("%d", max((int)str1.size(), (int)str2.size()));
  return 0;
}
