const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;
void (async function () {
const strA = await readline();
const strB = await readline();
const idxs = {};
for (let i = 0; i < strB.length; i++) {
idxs[strB[i]] = i;
}
const count = new Array(strB.length).fill(0);
for (let c of strA) {
const idx = idxs[c];
if (idx !== undefined && (idx === 0 || count[idx] < count[idx - 1]))
count[idx]++;
}
console.log(count[count.length - 1]);
})();