#include <bits/stdc++.h>
using namespace std;
int main() {
  int t = 1;
  while (t--) {
    string a, b;
    cin >> a >> b;
    long long int n, m, i, j, ans = -1;
    n = a.size();
    m = b.size();
    i = 0;
    j = 0;
    while (i < n && j < m) {
      if (a[i] == b[j]) {
        i++;
        j++;
      } else {
        i++;
      }
    }
    if (j < m) {
      ans = m;
    }
    string s = a;
    a = b;
    b = s;
    n = a.size();
    m = b.size();
    i = 0;
    j = 0;
    while (i < n && j < m) {
      if (a[i] == b[j]) {
        i++;
        j++;
      } else {
        i++;
      }
    }
    if (j < m) {
      ans = max(ans, m);
    }
    cout << ans << "\n";
  }
  return 0;
}
