import java.io.*;
import java.util.*;
import java.math.*;
import java.awt.geom.*;
import static java.lang.Math.*;
public class Solution implements Runnable {
static final long INF = Integer.MAX_VALUE / 2;
public void solve () throws Exception {
int n = nextInt();
String a = in.readLine();
String b = in.readLine();
if (a.compareTo(b) >= 0) {
out.println(-1);
return;
}
int m = max (a.length(), b.length());
long d [][] = new long [m + 10001][4];
d[0][0] = 1L;
for (int i = 0; i < m + 10000; i++) {
for (int state = 0; state < 4; state++) {
if (d[i][state] > 0) {
if (state == 0) {
if (i < a.length() && i < b.length()) {
int diff = b.charAt(i) - a.charAt(i);
if (diff == 0) {
d [i + 1][state] += d[i][state];
if (d[i + 1][state] > INF) {
d[i + 1][state] = INF;
}
} else if (diff >= 1) {
d[i + 1][1] += d[i][state];
if (d[i + 1][1] > INF) {
d[i + 1][1] = INF;
}
d[i + 1][2] += d[i][state];
if (d[i + 1][2] > INF) {
d[i + 1][2] = INF;
}
d[i + 1][3] += (long)(diff - 1) * d[i][state];
if (d[i + 1][3] > INF) {
d[i + 1][3] = INF;
}
}
} else if (i < a.length() && i >= b.length()) {
} else if (i >= a.length() && i < b.length()) {
int diff = b.charAt(i) - 'a';
d[i + 1][2] += d[i][state];
if (d[i + 1][2] > INF) {
d[i + 1][2] = INF;
}
d[i + 1][3] += (long) diff * d[i][state];
if (d[i + 1][3] > INF) {
d[i + 1][3] = INF;
}
} else {
d[i + 1][3] += d[i][state] * 26L;
if (d[i + 1][3] > INF) {
d[i + 1][3] = INF;
}
}
} else if (state == 1) {
if (i < a.length()) {
d[i + 1][state] += d[i][state];
if (d[i + 1][state] > INF) {
d[i + 1][state] = INF;
}
int diff = 'z' - a.charAt(i);
d[i + 1][3] += (long) diff * (d[i][state]);
if (d[i + 1][3] > INF) {
d[i + 1][3] = INF;
}
} else {
d[i + 1][3] += d[i][state] * 26L;
if (d[i + 1][3] > INF) {
d[i + 1][3] = INF;
}
}
} else if (state == 3) {
d[i + 1][state] += d[i][state] * 26L;
if (d[i + 1][state] > INF) {
d[i + 1][state] = INF;
}
} else if (state == 2) {
if (i < b.length()) {
d[i + 1][state] += d[i][state];
if (d[i + 1][state] > INF) {
d[i + 1][state] = INF;
}
int diff = b.charAt(i) - 'a';
d[i + 1][3] += (long) diff * d[i][state];
if (d[i + 1][3] > INF) {
d[i + 1][3] = INF;
}
} else {
//
}
}
}
}
}
long ans = 0;
for (int i = 1; i <= m + 10000; i++) {
if (n > 0) {
if (d[i][3] > n) {
ans += (long) n * i;
n = 0;
} else {
ans += (long) d[i][3] * i;
n -= d[i][3];
}
if (i < b.length()) {
if (d[i][2] > n) {
ans += (long) n * i;
n = 0;
} else {
ans += (long) d[i][2] * i;
n -= d[i][2];
}
}
}
}
if (n > 0) {
out.println(-1);
} else {
out.println(ans);
}
}
static final String fname = "dictionary";
static long stime = 0;
BufferedReader in;
PrintWriter out;
StringTokenizer st;
private String nextToken () throws Exception {
while (st == null || !st.hasMoreTokens()) {
st = new StringTokenizer(in.readLine());
}
return st.nextToken();
}
private int nextInt () throws Exception {
return Integer.parseInt(nextToken());
}
private long nextLong () throws Exception {
return Long.parseLong(nextToken());
}
private double nextDouble () throws Exception {
return Double.parseDouble(nextToken());
}
@Override
public void run() {
try {
in = new BufferedReader(new FileReader(fname+".in"));
out = new PrintWriter(new FileWriter(fname+".out"));
solve ();
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
out.close();
}
}
public static void main(String[] args) {
new Thread(null, new Solution(), "", 1<<25).start();
}
}