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

public class chemcode_aa {
	public static void main(String[] args) {
		new chemcode_aa().run();
	}

	BufferedReader br;
	StringTokenizer st;
	PrintWriter out;
	boolean eof = false;

	public void run() {
		Locale.setDefault(Locale.US);
		try {
			br = new BufferedReader(new FileReader(FNAME + ".in"));
			out = new PrintWriter(FNAME + ".out");
			solve();
			out.close();
		} catch (Throwable e) {
			e.printStackTrace();
			System.exit(566);
		}
	}

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

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

	void myAssert(boolean u, String message) {
		if (!u) {
			throw new Error("Assertion failed!!! " + message);
		}
	}

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

	String FNAME = "chemcode";

	private void solve() throws IOException {
		char[] s = nextToken().toCharArray();
		int n = nextInt();
		char[][] d = new char[n][];
		for (int i = 0; i < d.length; i++) {
			d[i] = nextToken().toCharArray();
		}
		int[] a = new int[s.length + 1];
		Arrays.fill(a, Integer.MAX_VALUE / 2);
		a[0] = 0;
		for (int i = 0; i + 1 < a.length; i++) {
			for (int j = 0; j < d.length; j++) {
				if (s[i] == d[j][0] || (d[j].length > 1 && s[i] == d[j][1])) {
					a[i + 1] = Math.min(a[i + 1], a[i] + 1);
				}
				if (i + 2 < a.length && d[j].length == 2 && d[j][0] == s[i]
						&& d[j][1] == s[i + 1]) {
					a[i + 2] = Math.min(a[i + 2], a[i] + 1);
				}
			}
		}
		if (a[s.length] < Integer.MAX_VALUE / 2) {
			out.println(a[s.length]);
		} else {
			out.println("-1");
		}
	}
}
