#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;

class BIT {
private:
	int size;
	vector<long long> bit;
	int mod;

public:
	BIT(int n, int m):size(n), bit(n + 1, 0), mod(m) {}

	void add(int i, int x) {
		while(i <= size) {
			bit[i] += x;
			bit[i] %= mod;
			i += i & -i;
		}
	}

	long long sum(int i) const {
		long long s = 0;
		while(i > 0) {
			s += bit[i];
			s %= mod;
			i -= i & -i;
		}
		return s;
	}
};

int main() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	for(int a, b, p; cin >> a >> b >> p && a;) {
		const int num = b - a + 2;

		vector<string> order;
		order.reserve(num);

		for(int i = a; i <= b; ++i) {
			order.emplace_back(to_string(i));
		}

		sort(order.begin(), order.end());

		BIT bit(num, p);
		bit.add(1, 1);

		for(const auto &s : order) {
			const int index = stoi(s) - a + 2;
			const auto tmp = bit.sum(index - 1);
			bit.add(index, tmp);
		}

		cout << (bit.sum(num) - 1 + p) % p << endl;
	}

	return EXIT_SUCCESS;
}