// Задача "Химический шифр"
// 3-я интернет-олимпиада сезона 2010-2011, базовый уровень
// Автор задачи: Антон Ахи, akhi@rain.ifmo.ru
// Автор решения: Роман Колганов, kolganov@gmail.com

import java.io.*;
import java.util.*;

public class chemcode_rk implements Runnable {
	public static void main(String[] args) {
		new Thread(new chemcode_rk()).start();
	}

	BufferedReader in;
	StringTokenizer st;
	PrintWriter out;

	public void run() {
		try {
			Locale.setDefault(Locale.US);
			String filename = "chemcode_rk".substring(0,
					"chemcode_rk".indexOf('_'));
			in = new BufferedReader(new FileReader(filename + ".in"));
			out = new PrintWriter(filename + ".out");
			solve();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		} finally {
			out.close();
		}
	}

	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(in.readLine());
			} catch (Exception e) {
				return "";
			}
		}
		return st.nextToken();
	}

	int nextInt() {
		return Integer.parseInt(nextToken());
	}

	void myAssert(boolean b, String message) {
		if (!b) {
			throw new Error(message);
		}
	}

	long inBounds(long x, long l, long r, String name) {
		myAssert(l <= x && x <= r, name + " is out of bounds: " + x
				+ " is not in [" + l + ", " + r + "]");
		return x;
	}

	final long MAXN = (long) 1e2;
	final String nosolution = "-1";

	void solve() {
		String s = nextToken();
		inBounds(s.length(), 1, MAXN, "|s|");
		for (int i = 0; i < s.length(); ++i) {
			myAssert(Character.isLetter(s.charAt(i)), "wrong symbol in s");
		}
		long n = inBounds(nextInt(), 1, MAXN, "n");
		boolean[][] pair = new boolean[Byte.MAX_VALUE][Byte.MAX_VALUE];
		boolean[] used = new boolean[Byte.MAX_VALUE];
		for (int i = 0; i < n; ++i) {
			String tmp = nextToken();
			inBounds(tmp.length(), 1, 2, "length of " + (i + 1)
					+ "-th element's name");
			myAssert(
					Character.isLetter(tmp.charAt(0))
							&& Character.isLetter(tmp.charAt(tmp.length() - 1)),
					"wrong symbol in " + (i + 1) + "-th element's name");
			used[tmp.charAt(0)] = true;
			if (tmp.length() == 2) {
				pair[tmp.charAt(0)][tmp.charAt(1)] = true;
				used[tmp.charAt(1)] = true;
			}
		}
		int i = 0;
		int res = 0;
		while (i < s.length()) {
			if (i < s.length() - 1 && pair[s.charAt(i)][s.charAt(i + 1)]) {
				++res;
				i += 2;
			} else if (used[s.charAt(i)]) {
				++res;
				++i;
			} else {
				out.println(nosolution);
				return;
			}
		}
		out.println(res);
	}
}
