One day Vasya was lying in bed watching his electronic clock to fall asleep quicker.Vasya lives in a strange country, where days have h hours, and every hour has m minutes. Clock shows time in decimal number system, in format H:M, where the string H always has a fixed length equal to the number of digits in the decimal representation of number h - 1. To achieve this, leading zeros are added if necessary. The string M has a similar format, and its length is always equal to the number of digits in the decimal representation of number m - 1. For example, if h = 17, m = 1000, then time equal to 13 hours and 75 minutes will be displayed as "13:075".Vasya had been watching the clock from h1 hours m1 minutes to h2 hours m2 minutes inclusive, and then he fell asleep. Now he asks you to count how many times he saw the moment at which at least k digits changed on the clock simultaneously.For example, when switching 04:19  →  04:20 two digits change. When switching 23:59  →  00:00, four digits change.Consider that Vasya has been watching the clock for strictly less than one day. Note that the last time Vasya saw on the clock before falling asleep was "h2:m2". That is, Vasya didn't see the moment at which time "h2:m2" switched to the next value.

The first line of the input file contains three space-separated integers h, m and k (2 ≤ h, m ≤ 109, 1 ≤ k ≤ 20). The second line contains space-separated integers h1, m1 (0 ≤ h1 < h, 0 ≤ m1 < m). The third line contains space-separated integers h2, m2 (0 ≤ h2 < h, 0 ≤ m2 < m).

Print a single number — the number of times Vasya saw the moment of changing at least k digits simultaneously. Please do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cin stream (also you may use the %I64d specificator).

NoteIn the first example Vasya will see the following moments of time: 4:4  0:0  →  0:1  →  0:2  →  0:3  →  0:4  1:0  →  1:1  →  1:2  →  1:3  →  1:4  2:0  →  2:1  →  2:2  →  2:3  →  2:4. Double arrow () marks the sought moments of time (in this example — when Vasya sees two numbers changing simultaneously).In the second example k = 1. Any switching time can be accepted, since during switching of the clock at least one digit is changed. Total switching equals to 24·60 = 1440, but Vasya have not seen one of them — the switching of 23:59  00:00.In the third example Vasya fell asleep immediately after he began to look at the clock, so he did not see any change.

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 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) {
		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();
	}
}