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

public class E {

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

    int hNum, mNum, k, newHourK;
    int newDayChange;

    long pow10;
    long pow10Hour;

    long go(int h, int m) {
        // good moments from (0, 0) to (h, m)
        //System.err.println(h + " " + m + " ");
        if (m < 0) {
            m += mNum;
            h--;
        }

        if (h < 0)
            return 0;

        long res = 0;

        // when hour doesn't change

        // first h full hours
        res += (long)h * ((mNum - 1) / pow10);

        //System.err.println(res);

        //last hour also full
        if (m == mNum - 1)
            res += (mNum - 1) / pow10;
        //last hour not full
        else
            res += (m + 1) / pow10;

        //hour also changes
        //in fact everything is the same, but we use newHourK instead of k
        if (m != mNum - 1)
            h--;

        //hour changes for hours [0, h]

        if (h == hNum - 1) {
            if (newDayChange >= newHourK)
                res++;
            h--;
        }
        // if it's full day, last change must be treated separately
        res += (h + 1) / pow10Hour;

        //System.err.println(res);

        return res;
    }

    void solve() throws IOException {
        hNum = nextInt();
        mNum = nextInt();
        k = nextInt();

        int h1 = nextInt();
        int m1 = nextInt();

        int h2 = nextInt();
        int m2 = nextInt();

        int newHourChange = 0;

        String s = Integer.toString(mNum - 1);
        for (int i = 0; i < s.length(); i++)
            if (s.charAt(i) != '0')
                newHourChange++;

        pow10 = 1;
        for (int i = 0; i < k - 1; i++)
            pow10 *= 10;

        newHourK = Math.max(k - newHourChange, 1);

        pow10Hour = 1;
        for (int i = 0; i < newHourK - 1; i++)
            pow10Hour *= 10;

        newDayChange = 0;
        s = Integer.toString(hNum - 1);
        for (int i = 0; i < s.length(); i++)
            if (s.charAt(i) != '0')
                newDayChange++;

        if (h1 < h2 || (h1 == h2 && m1 <= m2))
            // good moments from (h1,m1) to (h2,m2-1)
            out.print(go(h2, m2 - 1) - go(h1, m1 - 1));
        else
            // good moments from (h1, m1) to (hNum - 1, mNum - 1) and from (0, 0) to (h2, m2 - 1)
            out.print(go(hNum - 1, mNum - 1) - go(h1, m1 - 1) + go(h2, m2 - 1));
    }

    void inp() throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }

    public static void main(String[] args) throws IOException {
        new E().inp();
    }

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

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

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

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

}

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

public class Main {
	static Scanner in; static int next() throws Exception {return in.nextInt();}
	static PrintWriter out;
//	static StreamTokenizer in;

	static int h;
	static int m;
	static int k;

	static long count(int hh, int mm) {

		long answ = 0;

		String s = ((m - 1) + "");
		int cnt = 0;
		for (char cc : s.toCharArray()) if (cc != '0') cnt++;

        if (k <= cnt) {
        	answ += hh;
        } else {
        	int h0 = hh;
        	int kk = k - cnt;
        	for (int i = 0; i < kk - 1; i++) h0 /= 10;
        	answ += h0;
        }

		int c = ((m - 1) + "").length();

		if (k <= c) {
			int m0 = m - 1;

			for (int i = 0; i < k - 1; i++) m0 /= 10;

			for (int i = 0; i < k - 1; i++) mm /= 10;

			answ += (long) m0 * hh + mm;
		}

		return answ;
	}

	public static void main(String[] args) throws Exception {
		in = new Scanner(System.in);
		out = new PrintWriter(System.out);
//		in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));

		h = next();
		m = next();
		k = next();

		int h1 = next();
		int m1 = next();

		int h2 = next();
		int m2 = next();

//		out.println(count(h2, m2));
//		out.println(count(h1, m1));

		long answ = count(h2, m2) - count(h1, m1);

		if (h2 < h1 || (h2 == h1 && m2 < m1)) {
			answ += count(h - 1, m - 1);
			String s = (h - 1) + "" + (m - 1);
			int cnt = 0;
			for (char cc : s.toCharArray()) if (cc != '0') cnt++;
			if (cnt >= k) answ++;
		}

		out.println(answ);

		out.close();
	}
}

//package prac;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class R86E {
	InputStream is;
	PrintWriter out;
	String INPUT = "";

	void solve()
	{
//		for(int h = 0;h <= 1;h++){
//			for(int i = 0;i <= 100;i++){
//				tr(h, i, count(h, 12, i, 101));
//			}
//		}
//		tr(count(2, 12, 0, 60));

		int h = ni(), m = ni(), K = ni();
		int h1 = ni(), m1 = ni();
		int h2 = ni(), m2 = ni();
		if(h1 < h2 || (h1 == h2 && m1 <= m2)){
			out.println(count(h2, h, m2, m)[K] - count(h1, h, m1, m)[K]);
		}else{
//			tr(count(h-1, h, m-1, m));
//			tr(count(h, h, 0, m));
//			tr(count(h1, h, m1, m));
//			tr(count(h2, h, m2, m));
			out.println(count(h, h, 0, m)[K] - count(h1, h, m1, m)[K]
					 + count(h2, h, m2, m)[K]);
		}
	}

	long[] count(int h, int hlim, int m, int mlim)
	{
		long[] ret = new long[24];
		if(h == hlim){
			h--;
			m = mlim-1;
			int eh = 0;
			for(int u = hlim-1;u > 0;u/=10){
				if(u%10 != 0)eh++;
			}
			int ec = 0;
			for(int u = mlim-1;u > 0;u/=10){
				if(u%10 != 0)ec++;
			}
			ret[eh+ec]++;
		}
		long[] hdis = count(h, hlim);
		long[] mdis = count(m, mlim);
		long[] madis = count(mlim-1, mlim);

		int ec = 0;
		for(int u = mlim-1;u > 0;u/=10){
			if(u%10 != 0)ec++;
		}
		for(int i = 0;i < hdis.length;i++){
			ret[i+ec] += hdis[i];
		}
		for(int i = 0;i < mdis.length;i++){
			ret[i] += mdis[i] + madis[i] * h;
		}

		for(int i = ret.length-2;i >= 1;i--){
			ret[i] += ret[i+1];
		}

		return ret;
	}

	// 0->1, ..., m-1->m の分布
	long[] count(int m, int mlim)
	{
		long[] ret = new long[12];
		for(int i = 1, u = Math.min(m, mlim-1);i <= 10;i++, u/=10){
			ret[i] = u;
		}
		for(int i = 1;i <= 9;i++){
			ret[i] -= ret[i+1];
		}

		if(m == mlim){
			int ec = 0;
			for(int u = m;u > 0;u/=10){
				if(u%10 != 0)ec++;
			}
			ret[ec]++;
		}
		return ret;
	}

	void run() throws Exception
	{
		is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		tr(System.currentTimeMillis()-s+"ms");
	}

	public static void main(String[] args) throws Exception { new R86E().run(); }

	private byte[] inbuf = new byte[1024];
	private int lenbuf = 0, ptrbuf = 0;

	private int readByte()
	{
		if(lenbuf == -1)throw new InputMismatchException();
		if(ptrbuf >= lenbuf){
			ptrbuf = 0;
			try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
			if(lenbuf <= 0)return -1;
		}
		return inbuf[ptrbuf++];
	}

	private int ni()
	{
		int num = 0, b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
	private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}

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

public class Main {
	static Scanner in; static int next() throws Exception {return in.nextInt();}
	static PrintWriter out;
//	static StreamTokenizer in;

	static int h;
	static int m;
	static int k;

	static long count(int hh, int mm) {
		int c = ((m - 1) + "").length();

		if (k > c) {
			int kk = k;
			kk -= c;

			for (int i = 0; i < kk - 1; i++) hh /= 10;
			return hh;
		} else {
			int m0 = m;

			for (int i = 0; i < k - 1; i++) m0 /= 10;
			int m1 = m0;
			for (int i = 0; i < k - 1; i++) m1 *= 10;
			if (m1 < m) m0++;
			for (int i = 0; i < k - 1; i++) mm /= 10;

			return (long)m0 * hh + mm;
		}
	}

	public static void main(String[] args) throws Exception {
		in = new Scanner(System.in);
		out = new PrintWriter(System.out);
//		in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));

		h = next();
		m = next();
		k = next();

		int h1 = next();
		int m1 = next();

		int h2 = next();
		int m2 = next();

//		out.println(count(h2, m2));
//		out.println(count(h1, m1));

		long answ = count(h2, m2) - count(h1, m1);

		if (answ < 0) answ += count(h, 0);

		out.println(answ);

		out.close();
	}
}

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

public class Main {
	static Scanner in; static int next() throws Exception {return in.nextInt();}
	static PrintWriter out;
//	static StreamTokenizer in;

	static int h;
	static int m;
	static int k;

	static long count(int hh, int mm) {
		int c = ((m - 1) + "").length();

		if (k > c) {
			int kk = k;
			kk -= c;

			for (int i = 0; i < kk - 1; i++) hh /= 10;
			return hh;
		} else {
			int m0 = m;

			for (int i = 0; i < k - 1; i++) m0 /= 10;
			for (int i = 0; i < k - 1; i++) mm /= 10;

			return (long)m0 * hh + mm;
		}
	}

	public static void main(String[] args) throws Exception {
		in = new Scanner(System.in);
		out = new PrintWriter(System.out);
//		in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));

		h = next();
		m = next();
		k = next();

		int h1 = next();
		int m1 = next();

		int h2 = next();
		int m2 = next();

//		out.println(count(h2, m2));
//		out.println(count(h1, m1));

		long answ = count(h2, m2) - count(h1, m1);

		if (answ < 0) answ += count(h, 0);

		out.println(answ);

		out.close();
	}
}

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

public class Main {
	static Scanner in; static int next() throws Exception {return in.nextInt();}
	static PrintWriter out;
//	static StreamTokenizer in;

	static int h;
	static int m;
	static int k;

	static long count(int hh, int mm) {
		int c = ((m - 1) + "").length();

		if (k > c) {
			int kk = k;
			kk -= c;

			for (int i = 0; i < kk - 1; i++) hh /= 10;
			return hh;
		} else {
			int m0 = m;

			for (int i = 0; i < k - 1; i++) m0 /= 10;
			int m1 = m0;
			for (int i = 0; i < k - 1; i++) m1 *= 10;
			if (m1 < m) m0++;
			for (int i = 0; i < k - 1; i++) mm /= 10;

			return (long)m0 * hh + mm;
		}
	}

	public static void main(String[] args) throws Exception {
		in = new Scanner(System.in);
		out = new PrintWriter(System.out);
//		in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));

		h = next();
		m = next();
		k = next();

		int h1 = next();
		int m1 = next();

		int h2 = next();
		int m2 = next();

//		out.println(count(h2, m2));
//		out.println(count(h1, m1));

		long answ = count(h2, m2) - count(h1, m1);

		if (h2 < h1 || (h2 == h1 && m2 < m1)) answ += count(h - 1, m - 1) + 1;

		out.println(answ);

		out.close();
	}
}

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

public class Main {
	static Scanner in; static int next() throws Exception {return in.nextInt();}
	static PrintWriter out;
//	static StreamTokenizer in;

	static int h;
	static int m;
	static int k;

	static long count(int hh, int mm) {
		int c = ((m - 1) + "").length();

		if (k > c) {
			int kk = k;
			kk -= c;

			for (int i = 0; i < kk - 1; i++) hh /= 10;
			return hh;
		} else {
			int m0 = m;

			for (int i = 0; i < k - 1; i++) m0 /= 10;
			int m1 = m0;
			for (int i = 0; i < k - 1; i++) m1 *= 10;
			if (m1 < m) m0++;
			for (int i = 0; i < k - 1; i++) mm /= 10;

			return (long)m0 * hh + mm;
		}
	}

	public static void main(String[] args) throws Exception {
		in = new Scanner(System.in);
		out = new PrintWriter(System.out);
//		in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));

		h = next();
		m = next();
		k = next();

		int h1 = next();
		int m1 = next();

		int h2 = next();
		int m2 = next();

//		out.println(count(h2, m2));
//		out.println(count(h1, m1));

		long answ = count(h2, m2) - count(h1, m1);

		if (answ < 0) answ += count(h - 1, m - 1) + 1;

		out.println(answ);

		out.close();
	}
}