#include <bits/stdc++.h>

#define debug(x) cout << #x << " = " << x << endl
#define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++)
#define ford(i, ini, lim) for(int i = int(ini); i >= int(lim); i--)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef tuple<int, int, ll, int> query;

const int MAX = 1e5 + 5;
constexpr int SQRT_MAX = sqrt(MAX) + 5;
int BLOCK_SIZE;
int N, Q;
int a[MAX], b[MAX], ans[MAX];

typedef struct hull {
	int ptr;
	vector<int> slope, yy, id;

	hull() {
		ptr = 0;
	}

	inline bool bad(int l1, int l2, int l3) {
		return (((ll) (slope[l1] - slope[l3])) * ((ll) (yy[l2] - yy[l1]))) > (((ll) (slope[l1] - slope[l2])) * ((ll) (yy[l3] - yy[l1])));
	}

	void add(int m, int y, int i) {
		slope.push_back(m);
		yy.push_back(y);
		id.push_back(i);
		while((int) slope.size() >= 3 && bad(slope.size() - 3, slope.size() - 2, slope.size() - 1)) {
			slope.erase(slope.end() - 2);
			yy.erase(yy.end() - 2);
			id.erase(id.end() - 2);
		}
	}

	pair<ll, int> query(ll x) {
		if(ptr >= (int) slope.size()) {
			ptr = slope.size() - 1;
		}
		while(ptr < (int) slope.size() - 1 && slope[ptr] * x + yy[ptr] < slope[ptr + 1] * x + yy[ptr + 1]) {
			ptr++;
		}
		return make_pair(slope[ptr] * x + yy[ptr], id[ptr]);
	}

} hull;

hull hulls[SQRT_MAX];

int main() {
	scanf("%d %d", &N, &Q);
	fori(i, 1, N + 1) {
		scanf("%d %d", b + i, a + i);
	}

	BLOCK_SIZE = sqrt(N);
	vector<query> queries;
	fori(i, 1, Q + 1) {
		int l, r, t;
		scanf("%d %d %d", &l, &r, &t);
		queries.emplace_back(l, r, t, i);
	}
    /*
    l = 14178

	r = 99942

	t = 89269
*/
// cur -> 44720
// ans -> 67282

	int bid = 1;
	int start = 1;
	while(1) {
		int ending = min(N, BLOCK_SIZE * bid);
		vector< tuple<int, int, int> > guys;
		fori(i, start, ending + 1) {
			guys.emplace_back(a[i], b[i], i);
		}
		sort(guys.begin(), guys.end());
		for(auto &each : guys) {
			int aa, bb, id;
			tie(aa, bb, id) = each;
			hulls[bid].add(aa, bb, id);
		}
		if(ending == N) {
			break;
		}
		start = BLOCK_SIZE * bid + 1;
		bid++;
	}

	if(N == 100000) {
		ll cur = 44720;
		ll an = 67282;
		ll tt = 89269;
		debug(a[44720] * tt + b[44720]);
		debug(a[67282] * tt + b[67282]);
		int curblock = cur / BLOCK_SIZE + (cur % BLOCK_SIZE != 0);
		debug(curblock);
		debug(hulls[curblock].query(89629).first);
		debug(hulls[curblock].query(89629).first);
		int ansblock = an / BLOCK_SIZE + (an % BLOCK_SIZE != 0);
		debug(ansblock);
		debug(hulls[ansblock].query(89629).first);
		debug(hulls[ansblock].query(89629).first);
	}
	sort(queries.begin(), queries.end(), [] (const query &lhs, const query &rhs) {
		return get<2>(lhs) < get<2>(rhs);
	});

	for(auto &each : queries) {
		int l, r, id;
		ll t;
		tie(l, r, t, id) = each;
		int l_block = l / BLOCK_SIZE + (l % BLOCK_SIZE != 0);
		int r_block = r / BLOCK_SIZE + (r % BLOCK_SIZE != 0);
		ll best = -1;
		int idx = -1;
		int l_edge = (l_block == r_block) ? r : min(N, l_block * BLOCK_SIZE);
		int r_edge = (l_block == r_block) ? l : (r_block - 1) * BLOCK_SIZE + 1;
		fori(i, l, l_edge + 1) {
			if(a[i] * t + b[i] > best) {
				best = a[i] * t + b[i];
				idx = i;
			}
		}
		fori(i, r_edge, r + 1) {
			if(a[i] * t + b[i] > best) {
				best = a[i] * t + b[i];
				idx = i;
			}
		}
		l_block++;
		r_block--;
		fori(i, l_block, r_block + 1) {
			auto q = hulls[i].query(t);
			if(q.first > best) {
				best = q.first;
				idx = q.second;
			}
		}
		ans[id] = idx;
	}

	fori(i, 1, Q + 1) {
		printf("%d\n", ans[i]);
	}

	return 0;
}


#include <bits/stdc++.h>

#define debug(x) cout << #x << " = " << x << endl
#define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++)
#define ford(i, ini, lim) for(int i = int(ini); i >= int(lim); i--)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef tuple<int, int, ll, int> query;

const int MAX = 1e5 + 5;
constexpr int SQRT_MAX = sqrt(MAX) + 5;
int BLOCK_SIZE;
int N, Q;
int a[MAX], b[MAX], ans[MAX];

typedef struct hull {
	int ptr;
	vector<int> slope, yy, id;

	hull() {
		ptr = 0;
	}

	inline bool bad(int l1, int l2, int l3) {
		return (((ll) (slope[l1] - slope[l3])) * ((ll) (yy[l2] - yy[l1]))) > (((ll) (slope[l1] - slope[l2])) * ((ll) (yy[l3] - yy[l1])));
	}

	void add(int m, int y, int i) {
		slope.push_back(m);
		yy.push_back(y);
		id.push_back(i);
		while((int) slope.size() >= 3 && bad(slope.size() - 3, slope.size() - 2, slope.size() - 1)) {
			slope.erase(slope.end() - 2);
			yy.erase(yy.end() - 2);
			id.erase(id.end() - 2);
		}
	}

	pair<ll, int> query(ll x) {
		if(ptr >= (int) slope.size()) {
			ptr = slope.size() - 1;
		}
		while(ptr < (int) slope.size() - 1 && slope[ptr] * x + yy[ptr] < slope[ptr + 1] * x + yy[ptr + 1]) {
			ptr++;
		}
		if(N == 100000) {
			debug(slope[ptr]);
			debug(yy[ptr]);
		}
		return make_pair(slope[ptr] * x + yy[ptr], id[ptr]);
	}

} hull;

hull hulls[SQRT_MAX];

int main() {
	scanf("%d %d", &N, &Q);
	fori(i, 1, N + 1) {
		scanf("%d %d", b + i, a + i);
	}

	BLOCK_SIZE = sqrt(N);
	vector<query> queries;
	fori(i, 1, Q + 1) {
		int l, r, t;
		scanf("%d %d %d", &l, &r, &t);
		queries.emplace_back(l, r, t, i);
	}
    /*
    l = 14178

	r = 99942

	t = 89269
*/
// cur -> 44720
// ans -> 67282

	int bid = 1;
	int start = 1;
	while(1) {
		int ending = min(N, BLOCK_SIZE * bid);
		vector< tuple<int, int, int> > guys;
		fori(i, start, ending + 1) {
			guys.emplace_back(a[i], b[i], i);
		}
		sort(guys.begin(), guys.end());
		for(auto &each : guys) {
			int aa, bb, id;
			tie(aa, bb, id) = each;
			hulls[bid].add(aa, bb, id);
		}
		if(ending == N) {
			break;
		}
		start = BLOCK_SIZE * bid + 1;
		bid++;
	}

	if(N == 100000) {
		ll cur = 44720;
		ll an = 67282;
		ll tt = 89269;
		debug(a[44720] * tt + b[44720]);
		debug(a[44720]);
		debug(b[44720]);
		debug(a[67282] * tt + b[67282]);
		int curblock = cur / BLOCK_SIZE + (cur % BLOCK_SIZE != 0);
		debug(curblock);
		debug(hulls[curblock].query(89629).first);
		debug(hulls[curblock].query(89629).second);
		int ansblock = an / BLOCK_SIZE + (an % BLOCK_SIZE != 0);
		debug(ansblock);
		debug(hulls[ansblock].query(89629).first);
		debug(hulls[ansblock].query(89629).second);
	}

	sort(queries.begin(), queries.end(), [] (const query &lhs, const query &rhs) {
		return get<2>(lhs) < get<2>(rhs);
	});

	for(auto &each : queries) {
		int l, r, id;
		ll t;
		tie(l, r, t, id) = each;
		int l_block = l / BLOCK_SIZE + (l % BLOCK_SIZE != 0);
		int r_block = r / BLOCK_SIZE + (r % BLOCK_SIZE != 0);
		ll best = -1;
		int idx = -1;
		int l_edge = (l_block == r_block) ? r : min(N, l_block * BLOCK_SIZE);
		int r_edge = (l_block == r_block) ? l : (r_block - 1) * BLOCK_SIZE + 1;
		fori(i, l, l_edge + 1) {
			if(a[i] * t + b[i] > best) {
				best = a[i] * t + b[i];
				idx = i;
			}
		}
		fori(i, r_edge, r + 1) {
			if(a[i] * t + b[i] > best) {
				best = a[i] * t + b[i];
				idx = i;
			}
		}
		l_block++;
		r_block--;
		fori(i, l_block, r_block + 1) {
			auto q = hulls[i].query(t);
			if(q.first > best) {
				best = q.first;
				idx = q.second;
			}
		}
		ans[id] = idx;
	}

	fori(i, 1, Q + 1) {
		printf("%d\n", ans[i]);
	}

	return 0;
}


#include <bits/stdc++.h>

#define debug(x) cout << #x << " = " << x << endl
#define fori(i, ini, lim) for(ll i = ll(ini); i < ll(lim); i++)
#define ford(i, ini, lim) for(ll i = ll(ini); i >= ll(lim); i--)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll, ll> query;

const ll MAX = 1e5 + 5;
constexpr ll SQRT_MAX = sqrt(MAX) + 5;
ll BLOCK_SIZE;
ll N, Q;
ll a[MAX], b[MAX], ans[MAX];

typedef struct hull {
	ll ptr;
	vector<ll> slope, yy, id;

	hull() {
		ptr = 0;
	}

	inline bool bad(ll l1, ll l2, ll l3) {
		return (((ll) (slope[l1] - slope[l3])) * ((ll) (yy[l2] - yy[l1]))) > (((ll) (slope[l1] - slope[l2])) * ((ll) (yy[l3] - yy[l1])));
	}

	void add(ll m, ll y, ll i) {
		slope.push_back(m);
		yy.push_back(y);
		id.push_back(i);
		while((ll) slope.size() >= 3 && bad(slope.size() - 3, slope.size() - 2, slope.size() - 1)) {
			slope.erase(slope.end() - 2);
			yy.erase(yy.end() - 2);
			id.erase(id.end() - 2);
		}
	}

	pair<ll, ll> query(ll x) {
		if(ptr >= (ll) slope.size()) {
			ptr = slope.size() - 1;
		}
		while(ptr < (ll) slope.size() - 1 && slope[ptr] * x + yy[ptr] < slope[ptr + 1] * x + yy[ptr + 1]) {
			ptr++;
		}
		return make_pair(slope[ptr] * x + yy[ptr], id[ptr]);
	}

} hull;

hull hulls[SQRT_MAX];

int main() {
	scanf("%lld %lld", &N, &Q);
	fori(i, 1, N + 1) {
		scanf("%lld %lld", b + i, a + i);
	}

	BLOCK_SIZE = sqrt(N);
	vector<query> queries;
	fori(i, 1, Q + 1) {
		ll l, r, t;
		scanf("%lld %lld %lld", &l, &r, &t);
		queries.emplace_back(l, r, t, i);
	}

	ll bid = 1;
	ll start = 1;
	while(1) {
		ll ending = min(N, BLOCK_SIZE * bid);
		vector< tuple<ll, ll, ll> > guys;
		fori(i, start, ending + 1) {
			guys.emplace_back(a[i], b[i], i);
		}
		sort(guys.begin(), guys.end());
		for(auto &each : guys) {
			ll aa, bb, id;
			tie(aa, bb, id) = each;
			hulls[bid].add(aa, bb, id);
		}
		if(ending == N) {
			break;
		}
		start = BLOCK_SIZE * bid + 1;
		bid++;
	}

	sort(queries.begin(), queries.end(), [] (const query &lhs, const query &rhs) {
		return get<2>(lhs) < get<2>(rhs);
	});

	for(auto &each : queries) {
		ll l, r, id;
		ll t;
		tie(l, r, t, id) = each;
		ll l_block = l / BLOCK_SIZE + (l % BLOCK_SIZE != 0);
		ll r_block = r / BLOCK_SIZE + (r % BLOCK_SIZE != 0);
		ll best = -1;
		ll idx = -1;
		ll l_edge = (l_block == r_block) ? r : min(N, l_block * BLOCK_SIZE);
		ll r_edge = (l_block == r_block) ? l : (r_block - 1) * BLOCK_SIZE + 1;
		fori(i, l, l_edge + 1) {
			if(a[i] * t + b[i] > best) {
				best = a[i] * t + b[i];
				idx = i;
			}
		}
		fori(i, r_edge, r + 1) {
			if(a[i] * t + b[i] > best) {
				best = a[i] * t + b[i];
				idx = i;
			}
		}
		l_block++;
		r_block--;
		fori(i, l_block, r_block + 1) {
			auto q = hulls[i].query(t);
			if(q.first > best) {
				best = q.first;
				idx = q.second;
			}
		}
		ans[id] = idx;
	}

	fori(i, 1, Q + 1) {
		printf("%lld\n", ans[i]);
	}

	return 0;
}


#include <bits/stdc++.h>

#define debug(x) cout << #x << " = " << x << endl
#define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++)
#define ford(i, ini, lim) for(int i = int(ini); i >= int(lim); i--)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef tuple<int, int, ll, int> query;

const int MAX = 1e5 + 5;
constexpr int SQRT_MAX = sqrt(MAX) + 5;
int BLOCK_SIZE;
int N, Q;
int a[MAX], b[MAX], ans[MAX];

typedef struct hull {
	int ptr;
	vector<int> slope, yy, id;

	hull() {
		ptr = 0;
	}

	inline bool bad(int l1, int l2, int l3) {
		return (((ll) (slope[l1] - slope[l3])) * ((ll) (yy[l2] - yy[l1]))) > (((ll) (slope[l1] - slope[l2])) * ((ll) (yy[l3] - yy[l1])));
	}

	void add(int m, int y, int i) {
		slope.push_back(m);
		yy.push_back(y);
		id.push_back(i);
		while((int) slope.size() >= 3 && bad(slope.size() - 3, slope.size() - 2, slope.size() - 1)) {
			slope.erase(slope.end() - 2);
			yy.erase(yy.end() - 2);
			id.erase(id.end() - 2);
		}
	}

	pair<ll, int> query(ll x) {
		if(ptr >= (int) slope.size()) {
			ptr = slope.size() - 1;
		}
		while(ptr < (int) slope.size() - 1 && slope[ptr] * x + yy[ptr] <= slope[ptr + 1] * x + yy[ptr + 1]) {
			ptr++;
		}
		return make_pair(slope[ptr] * x + yy[ptr], id[ptr]);
	}

} hull;

hull hulls[SQRT_MAX];

int main() {
	scanf("%d %d", &N, &Q);
	fori(i, 1, N + 1) {
		scanf("%d %d", b + i, a + i);
	}

	BLOCK_SIZE = SQRT_MAX;
	vector<query> queries;
	fori(i, 1, Q + 1) {
		int l, r, t;
		scanf("%d %d %d", &l, &r, &t);
		queries.emplace_back(l, r, t, i);
	}

	int bid = 1;
	int start = 1;
	while(1) {
		int ending = min(N, BLOCK_SIZE * bid);
		vector< tuple<int, int, int> > guys;
		fori(i, start, ending + 1) {
			guys.emplace_back(a[i], b[i], i);
		}
		sort(guys.begin(), guys.end());
		for(auto &each : guys) {
			int aa, bb, id;
			tie(aa, bb, id) = each;
			hulls[bid].add(aa, bb, id);
		}
		if(ending == N) {
			break;
		}
		start = BLOCK_SIZE * bid + 1;
		bid++;
	}

	sort(queries.begin(), queries.end(), [] (const query &lhs, const query &rhs) {
		return get<2>(lhs) < get<2>(rhs);
	});

	for(auto &each : queries) {
		int l, r, id;
		ll t;
		tie(l, r, t, id) = each;
		int l_block = l / BLOCK_SIZE + (l % BLOCK_SIZE != 0);
		int r_block = r / BLOCK_SIZE + (r % BLOCK_SIZE != 0);
		ll best = -1;
		int idx = -1;
		int l_edge = (l_block == r_block) ? r : min(N, l_block * BLOCK_SIZE);
		int r_edge = (l_block == r_block) ? l : (r_block - 1) * BLOCK_SIZE + 1;
		fori(i, l, l_edge + 1) {
			if(a[i] * t + b[i] > best) {
				best = a[i] * t + b[i];
				idx = i;
			}
		}
		fori(i, r_edge, r + 1) {
			if(a[i] * t + b[i] > best) {
				best = a[i] * t + b[i];
				idx = i;
			}
		}
		l_block++;
		r_block--;
		fori(i, l_block, r_block + 1) {
			auto q = hulls[i].query(t);
			if(q.first > best) {
				best = q.first;
				idx = q.second;
			}
		}
		ans[id] = idx;
	}

	fori(i, 1, Q + 1) {
		printf("%d\n", ans[i]);
	}

	return 0;
}


#include <bits/stdc++.h>

#define debug(x) cout << #x << " = " << x << endl
#define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++)
#define ford(i, ini, lim) for(int i = int(ini); i >= int(lim); i--)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef tuple<int, int, ll, int> query;

const int MAX = 1e5 + 5;
constexpr int SQRT_MAX = sqrt(MAX) + 5;
int BLOCK_SIZE;
int N, Q;
int a[MAX], b[MAX], ans[MAX];

typedef struct hull {
	int ptr;
	vector<int> slope, yy, id;

	hull() {
		ptr = 0;
	}

	inline bool bad(int l1, int l2, int l3) {
		return (((ll) (slope[l1] - slope[l3])) * ((ll) (yy[l2] - yy[l1]))) > (((ll) (slope[l1] - slope[l2])) * ((ll) (yy[l3] - yy[l1])));
	}

	void add(int m, int y, int i) {
		slope.push_back(m);
		yy.push_back(y);
		id.push_back(i);
		while((int) slope.size() >= 3 && bad(slope.size() - 3, slope.size() - 2, slope.size() - 1)) {
			slope.erase(slope.end() - 2);
			yy.erase(yy.end() - 2);
			id.erase(id.end() - 2);
		}
	}

	pair<ll, int> query(ll x) {
		if(ptr >= (int) slope.size()) {
			ptr = slope.size() - 1;
		}
		while(ptr < (int) slope.size() - 1 && slope[ptr] * x + yy[ptr] < slope[ptr + 1] * x + yy[ptr + 1]) {
			ptr++;
		}
		return make_pair(slope[ptr] * x + yy[ptr], id[ptr]);
	}

} hull;

hull hulls[SQRT_MAX];

int main() {
	scanf("%d %d", &N, &Q);
	fori(i, 1, N + 1) {
		scanf("%d %d", b + i, a + i);
	}

	BLOCK_SIZE = sqrt(N);
	vector<query> queries;
	fori(i, 1, Q + 1) {
		int l, r, t;
		scanf("%d %d %d", &l, &r, &t);
		queries.emplace_back(l, r, t, i);
	}
    /*
    l = 14178

	r = 99942

	t = 89269
*/
// cur -> 44720
// ans -> 67282

	if(N == 10000) {
		debug(a[44720] * 89269 + b[44720]);
		debug(a[67282] * 89269 + b[67282]);
		int curblock = 44720 / BLOCK_SIZE + (44720 % BLOCK_SIZE != 0);
		debug(hulls[curblock].query(89629).first);
		debug(hulls[curblock].query(89629).first);
		int ansblock = 67282 / BLOCK_SIZE + (67282 % BLOCK_SIZE != 0);
		debug(hulls[ansblock].query(89629).first);
		debug(hulls[ansblock].query(89629).first);
	}

	int bid = 1;
	int start = 1;
	while(1) {
		int ending = min(N, BLOCK_SIZE * bid);
		vector< tuple<int, int, int> > guys;
		fori(i, start, ending + 1) {
			guys.emplace_back(a[i], b[i], i);
		}
		sort(guys.begin(), guys.end());
		for(auto &each : guys) {
			int aa, bb, id;
			tie(aa, bb, id) = each;
			hulls[bid].add(aa, bb, id);
		}
		if(ending == N) {
			break;
		}
		start = BLOCK_SIZE * bid + 1;
		bid++;
	}

	sort(queries.begin(), queries.end(), [] (const query &lhs, const query &rhs) {
		return get<2>(lhs) < get<2>(rhs);
	});

	for(auto &each : queries) {
		int l, r, id;
		ll t;
		tie(l, r, t, id) = each;
		int l_block = l / BLOCK_SIZE + (l % BLOCK_SIZE != 0);
		int r_block = r / BLOCK_SIZE + (r % BLOCK_SIZE != 0);
		ll best = -1;
		int idx = -1;
		int l_edge = (l_block == r_block) ? r : min(N, l_block * BLOCK_SIZE);
		int r_edge = (l_block == r_block) ? l : (r_block - 1) * BLOCK_SIZE + 1;
		fori(i, l, l_edge + 1) {
			if(a[i] * t + b[i] > best) {
				best = a[i] * t + b[i];
				idx = i;
			}
		}
		fori(i, r_edge, r + 1) {
			if(a[i] * t + b[i] > best) {
				best = a[i] * t + b[i];
				idx = i;
			}
		}
		l_block++;
		r_block--;
		fori(i, l_block, r_block + 1) {
			auto q = hulls[i].query(t);
			if(q.first > best) {
				best = q.first;
				idx = q.second;
			}
		}
		ans[id] = idx;
	}

	fori(i, 1, Q + 1) {
		printf("%d\n", ans[i]);
	}

	return 0;
}


#include <bits/stdc++.h>

#define debug(x) cout << #x << " = " << x << endl
#define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++)
#define ford(i, ini, lim) for(int i = int(ini); i >= int(lim); i--)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef tuple<int, int, int, int> query;

const int MAX = 1e5 + 5;
constexpr int SQRT_MAX = sqrt(MAX) + 5;
int BLOCK_SIZE;
int N, Q;
int a[MAX], b[MAX], ans[MAX];

typedef struct hull {
	int ptr;
	vector<int> slope, yy, id;

	hull() {
		ptr = 0;
	}

	inline bool bad(int l1, int l2, int l3) {
		return (((ll) (slope[l1] - slope[l3])) * ((ll) (yy[l2] - yy[l1]))) > (((ll) (slope[l1] - slope[l2])) * ((ll) (yy[l3] - yy[l1])));
	}

	void add(int m, int y, int i) {
		slope.push_back(m);
		yy.push_back(y);
		id.push_back(i);
		while((int) slope.size() >= 3 && bad(slope.size() - 3, slope.size() - 2, slope.size() - 1)) {
			slope.erase(slope.end() - 2);
			yy.erase(yy.end() - 2);
			id.erase(id.end() - 2);
		}
	}

	pair<ll, int> query(ll x) {
		if(ptr >= (int) slope.size()) {
			ptr = slope.size() - 1;
		}
		while(ptr < (int) slope.size() - 1 && slope[ptr] * x + yy[ptr] < slope[ptr + 1] * x + yy[ptr + 1]) {
			ptr++;
		}
		return make_pair(slope[ptr] * x + yy[ptr], id[ptr]);
	}

} hull;

hull hulls[SQRT_MAX];

int main() {
	scanf("%d %d", &N, &Q);
	fori(i, 1, N + 1) {
		scanf("%d %d", b + i, a + i);
	}

	BLOCK_SIZE = sqrt(N);
	vector<query> queries;
	fori(i, 1, Q + 1) {
		int l, r, t;
		scanf("%d %d %d", &l, &r, &t);
		queries.emplace_back(l, r, t, i);
	}

	int bid = 1;
	int start = 1;
	while(1) {
		int ending = min(N, BLOCK_SIZE * bid);
		vector< tuple<int, int, int> > guys;
		fori(i, start, ending + 1) {
			guys.emplace_back(a[i], b[i], i);
		}
		sort(guys.begin(), guys.end());
		for(auto &each : guys) {
			int aa, bb, id;
			tie(aa, bb, id) = each;
			hulls[bid].add(aa, bb, id);
		}
		if(ending == N) {
			break;
		}
		start = BLOCK_SIZE * bid + 1;
		bid++;
	}

	sort(queries.begin(), queries.end(), [] (const query &lhs, const query &rhs) {
		return get<2>(lhs) < get<2>(rhs);
	});

	for(auto &each : queries) {
		int l, r, id;
		ll t;
		tie(l, r, t, id) = each;
		int l_block = l / BLOCK_SIZE + (l % BLOCK_SIZE != 0);
		int r_block = r / BLOCK_SIZE + (r % BLOCK_SIZE != 0);
		int l_edge = -(1 << 30);
		int r_edge = 1 << 30;
		ll best = -1;
		int idx = -1;
		if(l_block == r_block) {
			fori(i, l, r + 1) {
				if(a[i] * t + b[i] > best) {
					best = a[i] * t + b[i];
					idx = i;
				}
			}
			ans[id] = idx;
			continue;
		}
		if(l != (l_block - 1) * BLOCK_SIZE + 1) {
			l_edge = min(N, l_block * BLOCK_SIZE);
			l_block++;
		}
		if(r != r_block * BLOCK_SIZE && r != N) {
			r_edge = (r_block - 1) * BLOCK_SIZE + 1;
			r_block--;
		}
		fori(i, l, l_edge + 1) {
			if(a[i] * t + b[i] > best) {
				best = a[i] * t + b[i];
				idx = i;
			}
		}
		fori(i, r_edge, r + 1) {
			if(a[i] * t + b[i] > best) {
				best = a[i] * t + b[i];
				idx = i;
			}
		}
		fori(i, l_block, r_block + 1) {
			auto q = hulls[i].query(t);
			if(q.first > best) {
				best = q.first;
				idx = q.second;
			}
		}
		ans[id] = idx;
	}

	fori(i, 1, Q + 1) {
		printf("%d\n", ans[i]);
	}

	return 0;
}


#include <bits/stdc++.h>
#define res resize
#define pb push_back

using namespace std;
vector <vector <pair <int, int>>> tree;
vector <int> tree1;
vector <int> k;
vector <int> b;
int inf = 1e9;
int divide(int a, int bb) {
    int delta = 0;
    if (bb == 0) {
        return inf;
    }
    if (a%bb != 0) {
        delta = 1;
    }
    if ((a > 0 && bb > 0) || (a < 0 && bb < 0)) {
        return a/bb + delta;
    }
    return -(abs(a)/abs(bb));
}
bool comp(pair <int, int> a, pair<int,int> bb) {
    if (a.first != bb.first) {
        return a.first > bb.first;
    }
    return b[a.second] < b[bb.second];
}
void build(int l, int r, int v) {
    if (l == r - 1) {
        tree[v].pb({-inf, l});
        tree1[v] = 0;
    } else {
        int m = (r + l)/2;
        build(l, m, v*2 + 1);
        build(m, r, v*2 + 2);
        vector <pair<int, int>> t(r - l);
        for (int i = l; i < r; i++) {
            t[i - l] = {k[i], i};
        }
        sort(t.begin(), t.end(), comp);
        tree[v].res(r - l);
        tree[v][0] = {-inf, t[0].second};
        int sz = 0;
        for (int i = 1; i < r - l; i++) {
            int a = t[i].second;
            int x;
            while (sz > -1) {
                x = divide(b[a] - b[tree[v][sz].second], k[tree[v][sz].second] - k[a]);
                if (x > tree[v][sz].first) {
                    break;
                }
                sz--;
            }
            if (x != inf) {
                tree[v][sz + 1] = {x, a};
                sz++;
            }
        }
        tree1[v] = sz;
    }
}
pair<int, int> gett(int v, int t) {
    int l = -1, r = tree1[v] + 1;
    while (r - l > 1) {
        int m = (r + l)/2;
        if (tree[v][m].first <= t) {
            l = m;
        } else {
            r = m;
        }
    }
    int a = tree[v][l].second;
    return {k[a]*t + b[a], a};
}
pair <int, int> get(int l, int r, int u, int w, int v, int time) {
    if (l >= w || r <= u) {
        return {0, 0};
    } else if (u <= l && w >= r) {
        return gett(v, time);
    } else {
        int m = (r + l)/2;
        pair <int, int> a = get(l, m, u, w, 2*v + 1, time);
        pair <int, int> b = get(m, r, u, w, 2*v + 2, time);
        if (a.first < b.first) {
            return a;
        } else {
            return b;
        }
    }
}
int main()
{   int n, q;
    cin >> n >> q;
    k.res(n);
    b.res(n);
    tree.res(4*n);
    tree1.res(4*n);
    for (int i = 0; i < n; i++) {
        cin >> b[i] >> k[i];
        b[i] = -b[i];
        k[i] = -k[i];
    }
    build(0, n, 0);
    for (int i = 0; i < q; i++) {
        int l, r, t;
        cin >> l >> r >> t;
        l--;
        pair<int, int> a =  get(0, n, l, r, 0, t);
        cout << a.second + 1 <<  "\n";
    }
    return 0;
}

/* Sun Mar 10 2019 11:04:05 GMT+0300 (MSK) */


#define _CRT_DISABLE_PERFCRIT_LOCKS
#pragma comment(linker, "/STACK:16777216")

#include <cctype>
#include <vector>
#include <map>
#include <set>
#include <complex>
#include <ctime>
#include <iostream>
#include <fstream>
#include <time.h>
#include <cmath>
#include <stack>
#include <stdio.h>
#include <list>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <random>

const long double PI(acos(-1.0));

#define pb push_back
#define mp(a,b) make_pair(a,b)
#define all(x) x.begin(), x.end()
#define sqr(x) ((x)*(x))
#define F first
#define S second
#define eps 1e-6
#define inf (int)(1e9+7)
#define infll (ll)(1e18+3)
#define sz(x) ((int)x.size())
#define bits(x) __builtin_popcount(x)
#define bitsl(x) __builtin_popcountll(x)

using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
typedef vector < ll > vll;
typedef vector<int> vi;
typedef pair < ll, ll > pll;
typedef pair < int, int > pii;
typedef int huint;

struct line{
    ll k, b, i;
    line() {}
    line(ll k, ll b, int i) : k(k), b(b), i(i) {}
};

bool comp(const line &a, const line &b) {
    return a.k > b.k;
}

struct hull{
    vector<pair<ld, int>> me;
    vector<line> lines;

    hull () {}

    void add(ll k, ll b, int it) {
        int i = sz(lines);
        lines.pb(line(k, b, it));
        while (1) {
            if (!sz(me)) {
                me.pb(mp(-infll, i));
                break;
            } else {
                line end = lines[me.back().S];
                if (k == end.k) {
                    if (b >= end.b) break;
                    else me.pop_back();
                } else {
                    ld x = (b - end.b + .0) / (end.k - k + .0);
                    if (x + eps < me.back().F)
                        me.pop_back();
                    else {
                        me.push_back(mp(x, i));
                        break;
                    }
                }
            }
        }
    }

    pair<ll, int> getmin(ll x) {
        int l = 0, r = sz(me) - 1;
        while (l < r) {
            int m = (l + r + 1) >> 1;
            if (me[m].F - eps > x) r = m - 1;
            else l = m;
        } return mp(lines[me[l].S].b + lines[me[l].S].k * x, lines[me[l].S].i);
    }
    ll size() { return sz(me); }
};

vector<hull> v;
vector<line> l;
int n, m, st;

int Q(int L, int R, ll x) {
    --L; --R;
    int ind = -1;
    ll mn = infll;
    hull tail = hull();
    vector<line> tmp;
    while (L % m != 0 && L < sz(l)) {
        tmp.pb(line(l[L].k, l[L].b, int(l[L].i)));
        ++L;
    }
    while (R + 1 % m != 0 && R >= L) {
        tmp.pb(line(l[R].k, l[R].b, int(l[R].i)));
        --R;
    }
    sort(all(tmp), comp);
    for (int i = 0; i<sz(tmp); ++i)
        tail.add(tmp[i].k, tmp[i].b, int(tmp[i].i));
    pair<ll, int> ans;
    if (sz(tail)) {
        ans = tail.getmin(x);
        ind = ans.S;
        mn = ans.F;
    }

    int block;
    while (L < R) {
        block = L / m;
        if (sz(v[block]))
            ans = v[block].getmin(x);
        if (sz(v[block]) && ans.F < mn) {
            mn = ans.F;
            ind = ans.S;
        }
        L += m;
    }
    return ind;
}

int main() {
#ifndef LOCAL_COMP
    //freopen("smoking.in", "r", stdin);
    //freopen("smoking.out", "w", stdout);
#else
    freopen("/Users/nikita/Desktop/acm/acm/input.txt", "r", stdin);
    //freopen("/Users/nikita/Desktop/acm/acm/output.txt", "w", stdout);
#endif
    //cout.precision(10);

    srand(unsigned(time(nullptr)));
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cout.precision(10);

    int q; scanf("%d%d", &n, &q);

    for (int i = 0; i<n; ++i) {
        int b, k; scanf("%d%d", &b, &k);
        l.pb(line(-k, -b, i));
    }

    m = 400;
    st = (n%m==0?n/m:n/m+1);
    v.resize(st);

    for (int i = 0; i<st; ++i) {
        vector<line> tmp;
        for (int j = 0; j<m; ++j) {
            int ind = i*m + j;
            if (ind >= n) break;
            tmp.pb(line(ll(l[ind].k), ll(l[ind].b), int(l[ind].i)));
        }
        sort(all(tmp), comp);
        for (int j = 0; j<m; ++j) {
            v[i].add(ll(tmp[j].k), ll(tmp[j].b), int(tmp[j].i));
        }

    }
    for (int i = 0; i<q; ++i) {
        int l, r, x; scanf("%d%d%d", &l, &r, &x);
        printf("%d\n", Q(l, r, x) + 1);
    }

#ifdef LOCAL_COMP
    cerr << "\n == TIME : " << clock() / ld(CLOCKS_PER_SEC) << " == " << endl;
#endif
}

// Thu Mar 24 2016 23:46:50 GMT+0300 (RTZ 2 (78<0))


//Author: Romanov Artem
#include <bits/stdc++.h>
//#define IN "input.txt"
//#define OUT "output.txt"

#define PI 3.14159265358979323846L
#define E 2.71828182845904523536L
#define EPS 1e-12L
#define D_INF HUGE_VALL
#define D_NINF (-HUGE_VALL)
#define T_MAX(T) std::numeric_limits<T>::max()
#define T_MIN(T) std::numeric_limits<T>::min()
#define m_p make_pair
#define r_s random_shuffle
#define l_b lower_bound
#define u_b upper_bound
#define e_r equal_range
#define b_s binary_search
#define s_u set_union
#define s_i set_intersection
#define s_d set_difference
#define l_c lexicographical_compare
#define n_p next_permutation
#define p_p prev_permutation
#define F first
#define S second
#define j0 j57552
#define j1 j77461
#define jn j29628
#define y0 y84678
#define y1 y53021
#define yn y91675

using namespace std;
typedef long double dbl;

struct line {
    int64_t k, b, id; dbl x;
    line(int64_t k = 0, int64_t b = 0, dbl x = D_NINF, int64_t id = 0) : b(b), k(k), x(x), id(id) { }
    bool operator<(const line& l) { return (k < l.k); }
};

int n, q, l, r, t;
const size_t MAXN = 100010,
             BSIZE = 320;
int64_t a[MAXN], b[MAXN], mx;
vector< line >* ar[BSIZE];
vector< line >* br[BSIZE];

pair< int64_t, int64_t > get_val(int64_t x, vector< line >* ch) {
    size_t l = 0, r = ch->size() - 1;
    if (ch->empty())
        return m_p(0, 0);
    if ((*ch)[r].x <= x)
        return m_p((*ch)[r].k * x + (*ch)[r].b, (*ch)[r].id);
    else {
        while(r > l + 1) {
            size_t m = (l + r) / 2;
            if ((*ch)[m].x > x)
                r = m;
            else
                l = m;
        }
        return m_p((*ch)[l].k * x + (*ch)[l].b, (*ch)[l].id);
    }
}

void add_line(int64_t k, int64_t c, vector< line >* ch, int64_t& id) {
    //if (ch->empty())
    //    ch->push_back(line(k, c, D_NINF, id));
    //else {
        //if (k == ch->back().k) {
        //    if (c >= ch->back().b) ch->pop_back();
        //    else return;
        //}
        //if (ch->empty())
        //    ch->push_back(line(k, c, D_NINF, id));
        //else if ((dbl) (ch->back().b - c) / (k - ch->back().k) > 0.0L) {
            while (true) {
                if (ch->empty()) {
                    ch->push_back(line(k, c, D_NINF, id));
                    return;
                }
                if (k == ch->back().k) {
                    if (c <= ch->back().b) ch->pop_back();
                    else return;
                }
                if (ch->empty()) {
                    ch->push_back(line(k, c, D_NINF, id));
                    return;
                }
                //if ((dbl) (ch->back().b - c) / (k - ch->back().k) < 0) {
                //    return;
                //}
                if (ch->size() > 1 && (dbl) (ch->back().b - c) / (k - ch->back().k) + EPS < ch->back().x) {
                    ch->pop_back();
                } else {
                    //ch->back().x = ;
                    ch->push_back(line(k, c, (dbl) (ch->back().b - c) / (k - ch->back().k), id));
                    return;
                };
            }
            while (ch->size() && (dbl) (ch->back().b - c) / (k - ch->back().k) + EPS > ch->back().x)
                ch->pop_back();
            ch->back().x = (dbl) (ch->back().b - c) / (k - ch->back().k);
            ch->push_back(line(k, c, D_NINF, id));
        //}
    //}
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(11);
    cout.setf(ios::fixed);
    srand((uint32_t) time(nullptr));
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#else
    #ifdef IN
    freopen(IN, "r", stdin);
#endif
#ifdef OUT
    freopen(OUT, "w", stdout);
#endif
#endif

    cin >> n >> q;
    for (int i = 0; i < BSIZE; ++i) {
        ar[i] = new vector< line >();
        br[i] = new vector< line >();
    }
    for (int64_t i = 0; i < n; ++i) {
        cin >> a[i] >> b[i];
        br[i / BSIZE]->push_back(line(b[i], a[i], 0, i));
    }
    for (int k = 0; k < BSIZE; ++k) {
        sort(br[k]->begin(), br[k]->end());
        for (int i = 0; i < br[k]->size(); ++i) {
            add_line(-(*br[k])[i].k, -(*br[k])[i].b, ar[k], (*br[k])[i].id);
        }
    }
    /*if (n == 100000) {
        cout << "dffsddf";
        for (int i = 0; i < BSIZE; ++i) {
            ar[i] = nullptr;
            br[i] = nullptr;
        }
        return 0;
    }*/
    for (int i = 0; i < q; ++i) {
        cin >> l >> r >> t;
        l--; r--;
        size_t ll = l / BSIZE,
               rr = r / BSIZE;
        int64_t ii = 0;
        mx = 0;
        for (size_t j = (size_t) l; j < min((ll + 1) * BSIZE, (size_t) r + 1); ++j) {
            if (mx < a[j] + b[j] * t) {
                mx = a[j] + b[j] * t;
                ii = (int64_t) j;
            }
        }
        for (size_t j = max(rr * BSIZE, (size_t) l); j <= r; ++j) {
            if (mx < a[j] + b[j] * t) {
                mx = a[j] + b[j] * t;
                ii = (int64_t) j;
            }
        }
        for (size_t j = ll + 1; j + 1 <= rr; ++j) {
            pair< int64_t, int64_t > tp = get_val(t, ar[j]);
            if (mx < -tp.F) {
                mx = -tp.F;
                ii = tp.S;
            }
        }
        cout << ii + 1 << endl;
    }
    for (int i = 0; i < BSIZE; ++i) {
        ar[i] = nullptr;
        br[i] = nullptr;
    }
    return 0;
}

// Thu Mar 24 2016 23:46:58 GMT+0300 (RTZ 2 (78<0))


#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <deque>
#include <cstdlib>
#include <iomanip>

using namespace std;

const int MAXN = 100500;
const long long inf = 1e9 + 7;
long long a[MAXN], b[MAXN];
long long l[MAXN], r[MAXN];
long double times[MAXN];
int n, q;

struct line
{
    long double k, b, x;
    int ind;
    line (long double _k, long double _b, long double _x, int _ind) : k(_k), b(_b), x(_x), ind(_ind) {};
    line () {};
};

vector <line> t[4 * MAXN];
vector <line> ch;
vector < pair< pair<long double, long double>, long long> > pzdc;

void add_line (vector <line> &ch, long double k, long double b, int i)
{
    line l (k,b,-inf, i);
    bool f = 0;
    while (1)
    {
        if (ch.size() == 0)
        {
            ch.push_back(l);
            return;
        }
        line prev = ch.back(); /// 2
        if (prev.k == l.k)
        {
            if (l.b <= prev.b)
                ch.pop_back();
            else return;
        }
        else
        {
            long double x = (l.b - prev.b)/(prev.k - l.k);

            if (x <= prev.x)
            {
                ch.pop_back();
            }
            else
            {
                l.x = x;
                ch.push_back(l);
                return ;
            }
        }
    }
}

pair<long double, int> get_val (int v, long double x)
{
    int l = 0;
    int r = t[v].size() - 1;
    /*if (t[v][l].x > x)
    {
        return make_pair(x * t[v][l].k + t[v][l].b, t[v][l].ind);
    }
    */
    if(t[v][r].x <= x)
        return make_pair(x * t[v][r].k + t[v][r].b, t[v][r].ind);
    while (r - l > 1)
    {
        int mid = (l + r) / 2;
        if (t[v][mid].x > x) r = mid;
        else l = mid;
    }
    return make_pair(x * t[v][l].k + t[v][l].b, t[v][l].ind);
}

int glob;

void build (int v, int l, int r)
{
    vector < pair< pair <long double, long double>, long long> > h;
    if (r == l + 1)
    {
        add_line(t[v], pzdc[l].first.first, pzdc[l].first.second, pzdc[l].second);
        return;
    }
    int mid = (l + r) / 2;

    build(v * 2 + 1, l, mid);
    build(v * 2 + 2, mid, r);

    h.clear();
    for (int j = l; j < r; j++)
    {
        h.push_back(pzdc[j]);
    }
    sort(h.begin(), h.end());
    reverse(h.begin(), h.end());

    for (int i = 0; i < h.size(); i++)
    {
        add_line(t[v], h[i].first.first, h[i].first.second, h[i].second);
    }
}

pair <long double, int> get_ans (int v, int l, int r, int ll, int rr, long double times)
{
    if (ll == l && rr == r)
    {
        return get_val(v,times);
    }

    int mid = (l + r) / 2;

    if (rr <= mid)
        return get_ans(v * 2 + 1, l, mid, ll, rr, times);
    if (ll >= mid)
        return get_ans(v * 2 + 2, mid, r, ll, rr, times);

    pair <long double, int> f1 = get_ans(v * 2 + 1, l, mid, ll, mid, times);
    pair <long double, int> f2 = get_ans(v * 2 + 2, mid, r, mid, rr, times);

    if (f1.first < f2.first)
    {
        return f1;
    }
    else
    {
        return f2;
    }

}

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    ios_base::sync_with_stdio(0);

    cin >> n >> q;

    for (int i = 0; i < n; i++)
    {
        cin >> a[i] >> b[i];
        a[i] *= -1;
        b[i] *= -1;
        pzdc.push_back(make_pair(make_pair(b[i],a[i]), i + 1));
    }
    build(0, 0, n);

    for (int i = 0; i < q; i++)
    {
        cin >> l[i] >> r[i] >> times[i];
        l[i]--;
        cout << get_ans(0, 0, n, l[i], r[i], times[i]).second << endl;
    }

    return 0;
}

// Thu Mar 24 2016 23:46:59 GMT+0300 (RTZ 2 (78<0))


#define _CRT_DISABLE_PERFCRIT_LOCKS
#pragma comment(linker, "/STACK:16777216")

#include <cctype>
#include <vector>
#include <map>
#include <set>
#include <complex>
#include <ctime>
#include <iostream>
#include <fstream>
#include <time.h>
#include <cmath>
#include <stack>
#include <stdio.h>
#include <list>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <random>

const long double PI(acos(-1.0));

#define pb push_back
#define mp(a,b) make_pair(a,b)
#define all(x) x.begin(), x.end()
#define sqr(x) ((x)*(x))
#define F first
#define S second
#define eps 1e-4
#define inf (int)(1e9+7)
#define infll (ll)(1e18+3)
#define sz(x) ((int)x.size())
#define bits(x) __builtin_popcount(x)
#define bitsl(x) __builtin_popcountll(x)

using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
typedef vector < ll > vll;
typedef vector<int> vi;
typedef pair < ll, ll > pll;
typedef pair < int, int > pii;
typedef int huint;

struct line{
    ll k, b, i;
    line() {}
    line(ll k, ll b, int i) : k(k), b(b), i(i) {}
};

bool comp(const line &a, const line &b) {
    return a.k > b.k;
}

struct hull{
    vector<pair<ld, int>> me;
    vector<line> lines;

    hull () {}

    void add(ll k, ll b, int it) {
        int i = sz(lines);
        lines.pb(line(k, b, it));
        while (1) {
            if (!sz(me)) {
                me.pb(mp(-infll, i));
                break;
            } else {
                line end = lines[me.back().S];
                if (k == end.k) {
                    if (b >= end.b) break;
                    else me.pop_back();
                } else {
                    ld x = (b - end.b + .0) / (end.k - k + .0);
                    if (x < me.back().F)
                        me.pop_back();
                    else {
                        me.push_back(mp(x, i));
                        break;
                    }
                }
            }
        }
    }

    pair<ll, int> getmin(ll x) {
        int l = 0, r = sz(me) - 1;
        while (l < r) {
            int m = (l + r + 1) >> 1;
            if (me[m].F > x) r = m - 1;
            else l = m;
        } return mp(lines[me[l].S].b + lines[me[l].S].k * x, lines[me[l].S].i);
    }
    ll size() { return sz(me); }
};

vector<hull> v;
vector<line> l;
int n, m, st;

int Q(int L, int R, ll x) {
    --L; --R;
    int ind = -1;
    ll mn = infll;
    hull tail = hull();
    vector<line> tmp;
    while (L % m != 0 && L < sz(l)) {
        tmp.pb(line(l[L].k, l[L].b, int(l[L].i)));
        ++L;
    }
    while (R + 1 % m != 0 && R >= L) {
        tmp.pb(line(l[R].k, l[R].b, int(l[R].i)));
        --R;
    }
    sort(all(tmp), comp);
    for (int i = 0; i<sz(tmp); ++i)
        tail.add(tmp[i].k, tmp[i].b, int(tmp[i].i));
    pair<ll, int> ans;
    if (sz(tail)) {
        ans = tail.getmin(x);
        ind = ans.S;
        mn = ans.F;
    }

    int block;
    while (L < R) {
        block = L / m;
        ans = v[block].getmin(x);
        if (ans.F < mn) {
            mn = ans.F;
            ind = ans.S;
        }
        L += m;
    }
    return ind;
}

int main() {
#ifndef LOCAL_COMP
    //freopen("smoking.in", "r", stdin);
    //freopen("smoking.out", "w", stdout);
#else
    freopen("/Users/nikita/Desktop/acm/acm/input.txt", "r", stdin);
    //freopen("/Users/nikita/Desktop/acm/acm/output.txt", "w", stdout);
#endif
    //cout.precision(10);

    srand(unsigned(time(nullptr)));
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cout.precision(10);

    int q; scanf("%d%d", &n, &q);

    for (int i = 0; i<n; ++i) {
        int b, k; scanf("%d%d", &b, &k);
        l.pb(line(-k, -b, i));
    }

    m = int(sqrt(n + .0) + 1);
    st = (n%m==0?n/m:n/m+1);
    v.resize(st);

    for (int i = 0; i<st; ++i) {
        for (int j = 0; j<m; ++j) {
            int ind = i*m + j;
            if (ind >= n) break;
            else v[i].add(ll(l[ind].k), ll(l[ind].b), int(l[ind].i));
        }
    }
    for (int i = 0; i<q; ++i) {
        int l, r, x; scanf("%d%d%d", &l, &r, &x);
        printf("%d\n", Q(l, r, x) + 1);
    }

#ifdef LOCAL_COMP
    cerr << "\n == TIME : " << clock() / ld(CLOCKS_PER_SEC) << " == " << endl;
#endif
}

// Thu Mar 24 2016 23:46:48 GMT+0300 (RTZ 2 (78<0))


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <set>
#include <queue>
#include <map>
#include <string>
#include <iomanip>
#define ll long long
#define eps 1e-10
#define mp make_pair
#define pb push_back
#define inf 1e9
#define vi vector<long long>
#define vvi vector<vi>
#define vii vector<pair<long long,long long> >
#define vvii vector<vii>
#define itn long long
using namespace std;

struct line
{
	long long k, b, fp;
	line(){}
	line(long long k1, long long b1, long long fp1)
	{
		k = k1; b = b1; fp = fp1;
	}
};
long long n, sqrtn;

vii b;

vector<vector<line> > ch;

double dist(line a, line b)
{
	double k = (double)(a.b - b.b) / (double)(b.k - a.k);
	return k;
}

void add_line(long long a, long long b, long long i, long long fd)
{
	line newl = line(a, b, fd);
	while (true)
	{
		if (ch[i].size() == 0)
		{
			ch[i].push_back(newl);
			break;
		}
		if (ch[i].back().k == newl.k)
		{
			if (ch[i].back().b > newl.b)
				ch[i].pop_back();
			else
				break;
			continue;
		}
		if (ch[i].size() <= 1)
		{
			ch[i].push_back(newl);
			break;
		}
		else
		{
			line l = ch[i].back();
			line l1 = ch[i][ch[i].size() - 2];
			double a1 = dist(newl, l1), a2 = dist(l, l1);
			if (a1 < a2)
			{
				ch[i].pop_back();
				continue;
			}
			else
			{
				ch[i].push_back(newl);
				break;
			}
		}
	}
}

bool mycmp(pair<pair<long long, long long>, long long> a, pair<pair<long long, long long>, long long> b)
{
	return a.first.first > b.first.first;
}

double retres(long long x, long long i)
{
	if (x == 0)
		return 0;
	return dist(ch[i][x - 1], ch[i][x]);
}

pair<long long,long long> result(long long a, long long i)
{
	long long l = 0, r = ch[i].size() - 1;
	if (retres(l, i) - a > eps)
		return mp((long long)ch[i][l].k*a + (long long)ch[i][l].b, ch[i][l].fp);
	if (a - retres(r, i)>-eps)
		return mp((long long)ch[i][r].k*a + (long long)ch[i][r].b, ch[i][r].fp);
	while (r - l > 1)
	{
		long long m = r + l;
		m /= 2;
		if (retres(m, i) <= a)
		{
			l = m;
		}
		else
		{
			r = m;
		}
	}
	return mp((long long)ch[i][l].k*a + (long long)ch[i][l].b, ch[i][l].fp);
}

long long returnresult(long long l, long long r, long long t)
{
	long long ans = 1e18;
	long long tans = 0;
	long long now = 0;
	for (long long i = 0; i < ch.size(); now += sqrtn, ++i)
	{
		if (l > now && l < now + sqrtn)
		{
			for (long long j = l; j < min(now + (long long)sqrtn, r + 1); j++)
			{
				long long ans1 = b[j].first*t + b[j].second;
				if (ans1 < ans)
				{
					tans = j+1;
					ans = min(ans, ans1);
				}
			}
			continue;
		}
		if (now>=l && now + sqrtn <= r)
		{
			pair<long long, long long> asq = result(t, i);
			if (asq.first < ans)
			{
				tans = asq.second;
				ans = asq.first;
			}
			continue;
		}
		if (r >= now && r < now + sqrtn)
		{
			for (long long j = now; j <=r; j++)
			{
				long long ans1 = b[j].first*t + b[j].second;
				if (ans1 < ans)
				{
					tans = j+1;
					ans = min(ans, ans1);
				}
			}
			break;
		}
	}
	return tans;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie();
	//prepare();
	cin >> n;

	long long q;
	cin >> q;
	sqrtn = 1024;
	long long ansdf = (n/sqrtn);
	if (n - ansdf*sqrtn!= 0)
		ansdf++;
	ch.resize(ansdf);
	b.resize(n);
	for (long long i = 0; i < n; i++)
	{
		cin >> b[i].second >> b[i].first;
		b[i].first = -b[i].first;
		b[i].second = -b[i].second;
	}
	vector<pair<pair<long long, long long>, long long> > bsort(b.size());
	for (long long i = 0; i < n; i++)
	{
		bsort[i].first = b[i];
		bsort[i].second = i + 1;
	}

	long long num = 0;//
	for (long long i = 0; i < ch.size(); i++)
	{
		sort(bsort.begin() + i*sqrtn, bsort.begin() + min(n, (i + 1)*sqrtn),mycmp);
		for (long long j = 0; j < sqrtn; j++)
		{
			if (num == n)
				break;
			add_line(bsort[num].first.first, bsort[num].first.second, i, bsort[num].second);
			num++;
		}
	}

	for (long long i = 0; i < q; i++)
	{
		long long l, r, t;
		cin >> l >> r >> t;
		l--; r--;
		cout << returnresult(l, r, t) << endl;
	}

	return 0;
}

// Thu Jan 28 2016 18:08:53 GMT+0300 (MSK)


#define _CRT_DISABLE_PERFCRIT_LOCKS
#pragma comment(linker, "/STACK:16777216")

#include <cctype>
#include <vector>
#include <map>
#include <set>
#include <complex>
#include <ctime>
#include <iostream>
#include <fstream>
#include <time.h>
#include <cmath>
#include <stack>
#include <stdio.h>
#include <list>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <random>

const long double PI(acos(-1.0));

#define pb push_back
#define mp(a,b) make_pair(a,b)
#define all(x) x.begin(), x.end()
#define sqr(x) ((x)*(x))
#define F first
#define S second
#define eps 1e-4
#define inf (int)(1e9+7)
#define infll (ll)(1e18+3)
#define sz(x) ((int)x.size())
#define bits(x) __builtin_popcount(x)
#define bitsl(x) __builtin_popcountll(x)

using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
typedef vector < ll > vll;
typedef vector<int> vi;
typedef pair < ll, ll > pll;
typedef pair < int, int > pii;
typedef int huint;

struct line{
    ll k, b, i;
    line() {}
    line(ll k, ll b, int i) : k(k), b(b), i(i) {}
};

bool comp(const line &a, const line &b) {
    return a.k > b.k;
}

struct hull{
    vector<pair<ld, int>> me;
    vector<line> lines;

    hull () {}

    void add(ll k, ll b, int it) {
        int i = sz(lines);
        lines.pb(line(k, b, it));
        while (1) {
            if (!sz(me)) {
                me.pb(mp(-infll, i));
                break;
            } else {
                line end = lines[me.back().S];
                if (k == end.k) {
                    if (b >= end.b) break;
                    else me.pop_back();
                } else {
                    ld x = (b - end.b + .0) / (end.k - k + .0);
                    if (x < me.back().F)
                        me.pop_back();
                    else {
                        me.push_back(mp(x, i));
                        break;
                    }
                }
            }
        }
    }

    pair<ll, int> getmin(ll x) {
        int l = 0, r = sz(me) - 1;
        while (l < r) {
            int m = (l + r + 1) >> 1;
            if (me[m].F > x) r = m - 1;
            else l = m;
        } return mp(lines[me[l].S].b + lines[me[l].S].k * x, lines[me[l].S].i);
    }
    ll size() { return sz(me); }
};

vector<hull> v;
vector<line> l;
int n, m, st;

int Q(int L, int R, ll x) {
    --L; --R;
    int ind = -1;
    ll mn = infll;
    hull tail = hull();
    vector<line> tmp;
    while (L % m != 0 && L < sz(l)) {
        tmp.pb(line(l[L].k, l[L].b, int(l[L].i)));
        ++L;
    }
    while (R + 1 % m != 0 && R >= L) {
        tmp.pb(line(l[R].k, l[R].b, int(l[R].i)));
        --R;
    }
    sort(all(tmp), comp);
    for (int i = 0; i<sz(tmp); ++i)
        tail.add(tmp[i].k, tmp[i].b, int(tmp[i].i));
    pair<ll, int> ans;
    if (sz(tail)) {
        ans = tail.getmin(x);
        ind = ans.S;
        mn = ans.F;
    }

    if (L > R && (R - L + 1) % m != 0) while (1) {}

    int block;
    while (L < R) {
        block = L / m;
        ans = v[block].getmin(x);
        if (ans.F < mn) {
            mn = ans.F;
            ind = ans.S;
        }
        L += m;
    }
    return ind;
}

int main() {
#ifndef LOCAL_COMP
    //freopen("smoking.in", "r", stdin);
    //freopen("smoking.out", "w", stdout);
#else
    freopen("/Users/nikita/Desktop/acm/acm/input.txt", "r", stdin);
    //freopen("/Users/nikita/Desktop/acm/acm/output.txt", "w", stdout);
#endif
    //cout.precision(10);

    srand(unsigned(time(nullptr)));
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cout.precision(10);

    int q; scanf("%d%d", &n, &q);

    for (int i = 0; i<n; ++i) {
        int b, k; scanf("%d%d", &b, &k);
        l.pb(line(-k, -b, i));
    }

    m = 400;
    st = (n%m==0?n/m:n/m+1);
    v.resize(st);

    for (int i = 0; i<st; ++i) {
        vector<line> tmp;
        for (int j = 0; j<m; ++j) {
            int ind = i*m + j;
            if (ind >= n) break;
            else tmp.pb(l[ind]);
        }

        sort(all(tmp), comp);

        for (int j = 0; j<m; ++j) {
            int ind = i*m + j;
            if (ind >= n) break;
            v[i].add(tmp[j].k, tmp[j].b, tmp[j].i);
        }
    }
    for (int i = 0; i<q; ++i) {
        int l, r, x; scanf("%d%d%d", &l, &r, &x);
        printf("%d\n", Q(l, r, x) + 1);
    }

#ifdef LOCAL_COMP
    cerr << "\n == TIME : " << clock() / ld(CLOCKS_PER_SEC) << " == " << endl;
#endif
}

// Thu Mar 24 2016 23:46:51 GMT+0300 (RTZ 2 (78<0))


#define _CRT_DISABLE_PERFCRIT_LOCKS
#pragma comment(linker, "/STACK:16777216")

#include <cctype>
#include <vector>
#include <map>
#include <set>
#include <complex>
#include <ctime>
#include <iostream>
#include <fstream>
#include <time.h>
#include <cmath>
#include <stack>
#include <stdio.h>
#include <list>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <random>

const long double PI(acos(-1.0));

#define pb push_back
#define mp(a,b) make_pair(a,b)
#define all(x) x.begin(), x.end()
#define sqr(x) ((x)*(x))
#define F first
#define S second
#define eps 1e-4
#define inf (int)(1e9+7)
#define infll (ll)(1e18+3)
#define sz(x) ((int)x.size())
#define bits(x) __builtin_popcount(x)
#define bitsl(x) __builtin_popcountll(x)

using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
typedef vector < ll > vll;
typedef vector<int> vi;
typedef pair < ll, ll > pll;
typedef pair < int, int > pii;
typedef int huint;

struct line{
    ll k, b, i;
    line() {}
    line(ll k, ll b, int i) : k(k), b(b), i(i) {}
};

bool comp(const line &a, const line &b) {
    return a.k > b.k;
}

struct hull{
    vector<pair<ld, int>> me;
    vector<line> lines;

    hull () {}

    void add(ll k, ll b, int it) {
        int i = sz(lines);
        lines.pb(line(k, b, it));
        while (1) {
            if (!sz(me)) {
                me.pb(mp(-infll, i));
                break;
            } else {
                line end = lines[me.back().S];
                if (k == end.k) {
                    if (b >= end.b) break;
                    else me.pop_back();
                } else {
                    ld x = (b - end.b + .0) / (end.k - k + .0);
                    if (x < me.back().F)
                        me.pop_back();
                    else {
                        me.push_back(mp(x, i));
                        break;
                    }
                }
            }
        }
    }

    pair<ll, int> getmin(ll x) {
        int l = 0, r = sz(me) - 1;
        while (l < r) {
            int m = (l + r + 1) >> 1;
            if (me[m].F > x) r = m - 1;
            else l = m;
        } return mp(lines[me[l].S].b + lines[me[l].S].k * x, lines[me[l].S].i);
    }
    ll size() { return sz(me); }
};

vector<hull> v;
vector<line> l;
int n, m, st;

int Q(int L, int R, ll x) {
    --L; --R;
    int ind = -1;
    ll mn = infll;
    hull tail = hull();
    int _L = 0;
    pair<ll, int> ans;
    while (_L < L) _L += m;
    while (_L + m - 1 <= R) {
        int block = _L/m;
        ans = v[block].getmin(x);
        if (ans.F < mn) {
            ind = ans.S;
            mn = ans.F;
        }
        _L += m;
    }
    vector<line> tmp;
    for (;L % m != 0 && L <= R; ++L) tmp.pb(l[L]);
    while (_L <= R) tmp.pb(l[_L++]);
    sort(all(tmp), comp);
    for (int i = 0; i<sz(tmp); ++i)
        tail.add(tmp[i].k, tmp[i].b, tmp[i].i);
    if (sz(tail)) ans = tail.getmin(x);
    if (sz(tail) && ans.F < mn) {
        ind = ans.S;
        mn = ans.F;
    }
    return ind;
}

int main() {
#ifndef LOCAL_COMP
    //freopen("smoking.in", "r", stdin);
    //freopen("smoking.out", "w", stdout);
#else
    freopen("/Users/nikita/Desktop/acm/acm/input.txt", "r", stdin);
    //freopen("/Users/nikita/Desktop/acm/acm/output.txt", "w", stdout);
#endif
    //cout.precision(10);

    srand(unsigned(time(nullptr)));
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cout.precision(10);

    int q; scanf("%d%d", &n, &q);

    for (int i = 0; i<n; ++i) {
        int b, k; scanf("%d%d", &b, &k);
        l.pb(line(-k, -b, i));
    }

    m = 1000;
    st = (n%m==0?n/m:n/m+1);
    v.resize(st);

    for (int i = 0; i<st; ++i) {
        vector<line> tmp;
        for (int j = 0; j<m; ++j) {
            int ind = i*m + j;
            if (ind >= n) break;
            else tmp.pb(l[ind]);
        }

        sort(all(tmp), comp);

        for (int j = 0; j<m; ++j) {
            int ind = i*m + j;
            if (ind >= n) break;
            v[i].add(tmp[j].k, tmp[j].b, tmp[j].i);
        }
    }
    for (int i = 0; i<q; ++i) {
        int l, r, x; scanf("%d%d%d", &l, &r, &x);
        printf("%d\n", Q(l, r, x) + 1);
    }

#ifdef LOCAL_COMP
    cerr << "\n == TIME : " << clock() / ld(CLOCKS_PER_SEC) << " == " << endl;
#endif
}

// Thu Mar 24 2016 23:46:52 GMT+0300 (RTZ 2 (78<0))


#include <bits/stdc++.h>
using namespace std;

const int N = 100011;
typedef long long intl;

struct Point
{
	intl x, y;
	int id;
	Point operator -(Point p) {
		return {x - p.x, y - p.y, -1};
	}
	bool operator <(Point p) const {
		return tie(x, y, id) < tie(p.x, p.y, p.id);
	}
	intl cross(Point p) {
		return x * p.y - y * p.x;
	}
	intl y_inter(intl k) {
		return -k * x + y;
	}
}p[N];
intl xmul(Point a, Point b, Point c)
{
	return (b - a).cross(c - a);
}

vector <Point> convex(int l, int r)
{
	static Point q[N];
	vector <Point> ret;
	int n = r - l;
	copy(p + l, p + r, q);
	sort(q, q + n);
	for(int i = 0; i < n; i ++)
		if(i == n - 1 || q[i].x < q[i + 1].x)
		{
			while(ret.size() >= 2 &&
				xmul(*++ret.rbegin(), *ret.rbegin(), q[i]) >= 0)
				ret.pop_back();
			ret.push_back(q[i]);
		}
	return ret;
}

struct SegTree
{
	int l[N << 2], r[N << 2];
	vector <Point> cv[N << 2];
	void init(int left, int right, int x = 1)
	{
		l[x] = left;
		r[x] = right;
		cv[x] = convex(left, right);
		/*
		cout << "------\n";
		cout << x << ' ' << left << ' ' << right << '\n';
		for(auto &p : cv[x])
			cout << p.x << ' ' << p.y << ' ' << p.id << '\n';
			*/
		if(left + 1 != right)
		{
			int mid = (left + right) / 2;
			init(left, mid, 2 * x);
			init(mid, right, 2 * x + 1);
		}
	}
	Point query(intl k, vector <Point> &cv)
	{
		int n = cv.size();
		int left = 0, right = n;
		while(left + 1 < right)
		{
			int mid = (left + right) / 2;
			if(cv[mid - 1].y_inter(k) > cv[mid].y_inter(k))
				right = mid;
			else
				left = mid;
		}
		return cv[left];
	}
	Point query(int left, int right, intl k, int x = 1)
	{
		if(x > 20)
			return {0, 0, 0};
		if(l[x] == left && r[x] == right)
			return query(k, cv[x]);
		int mid = (l[x] + r[x]) / 2;
		if(right <= mid)
			return query(left, right, k, 2 * x);
		else if(left >= mid)
			return query(left, right, k, 2 * x + 1);
		else
		{
			Point p1 = query(left, mid, k, 2 * x);
			Point p2 = query(mid, right, k, 2 * x + 1);
			return (p1.y_inter(k) > p2.y_inter(k)) ? p1 : p2;
		}
	}
}st;

int main()
{
	ios :: sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	for(int i = 1; i <= n; i ++)
	{
		cin >> p[i].y >> p[i].x;
		p[i].id = i;
	}
	st.init(1, n + 1);

	while(m --)
	{
		int l, r, k;
		cin >> l >> r >> k;
		cout << st.query(l, r + 1, -k).id << '\n';
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int N = 100011;
typedef long long intl;

struct Point
{
	intl x, y;
	int id;
	Point operator -(Point p) {
		return {x - p.x, y - p.y, -1};
	}
	bool operator <(Point p) const {
		return tie(x, y, id) < tie(p.x, p.y, p.id);
	}
	intl cross(Point p) {
		return x * p.y - y * p.x;
	}
	intl y_inter(intl k) {
		return -k * x + y;
	}
}p[N];
intl xmul(Point a, Point b, Point c)
{
	return (b - a).cross(c - a);
}

vector <Point> convex(int l, int r)
{
	static Point q[N];
	vector <Point> ret;
	int n = r - l;
	copy(p + l, p + r, q);
	sort(q, q + n);
	for(int i = 0; i < n; i ++)
		if(i == n - 1 || q[i].x < q[i + 1].x)
		{
			while(ret.size() >= 2 &&
				xmul(*++ret.rbegin(), *ret.rbegin(), q[i]) >= 0)
				ret.pop_back();
			ret.push_back(q[i]);
		}
	return ret;
}

struct SegTree
{
	int l[N << 2], r[N << 2];
	vector <Point> cv[N << 2];
	void init(int left, int right, int x = 1)
	{
		l[x] = left;
		r[x] = right;
		cv[x] = convex(left, right);
		/*
		cout << "------\n";
		cout << x << ' ' << left << ' ' << right << '\n';
		for(auto &p : cv[x])
			cout << p.x << ' ' << p.y << ' ' << p.id << '\n';
			*/
		if(left + 1 != right)
		{
			int mid = (left + right) / 2;
			init(left, mid, 2 * x);
			init(mid, right, 2 * x + 1);
		}
	}
	Point query(intl k, vector <Point> &cv)
	{
		int n = cv.size();
		int left = 0, right = n;
		while(left + 1 < right)
		{
			int mid = (left + right) / 2;
			if(cv[mid - 1].y_inter(k) > cv[mid].y_inter(k))
				right = mid;
			else
				left = mid;
		}
		return cv[left];
	}
	Point query(int left, int right, intl k, int x = 1)
	{
		if(l[x] == left && r[x] == right)
			return query(k, cv[x]);
		int mid = (l[x] + r[x]) / 2;
		if(right <= mid)
			return query(left, right, k, 2 * x);
		else if(left >= mid)
			return query(left, right, k, 2 * x + 1);
		else
		{
			Point p1 = query(left, mid, k, 2 * x);
			Point p2 = query(mid, right, k, 2 * x + 1);
			return (p1.y_inter(k) > p2.y_inter(k)) ? p1 : p2;
		}
	}
}st;

int main()
{
	ios :: sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	for(int i = 1; i <= n; i ++)
	{
		cin >> p[i].y >> p[i].x;
		p[i].id = i;
	}
	st.init(1, n + 1);

	while(m --)
	{
		int l, r, k;
		cin >> l >> r >> k;
		cout << st.query(l, r + 1, -k).id << '\n';
	}

	return 0;
}


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

public class Codeforces
{
    public static void main(String args[])throws Exception
    {
        BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb=new StringBuilder();
        char s[]=bu.readLine().toCharArray();
        char t[]=bu.readLine().toCharArray();
        ArrayList<Integer> c[]=new ArrayList[26];
        int i,ans=0,cn[]=new int[26];
        for(i=0;i<26;i++)
        c[i]=new ArrayList<>();

        for(i=0;i<s.length;i++)
        c[s[i]-'a'].add(i);

        for(i=0;i<t.length;i++)
        cn[t[i]-'a']++;

        boolean pos=true;
        for(i=0;i<26;i++)
        if(cn[i]!=0 && c[i].size()==0) {pos=false; break;}
        if(!pos) {System.out.print("-1"); return;}

        ans=1;
        int cur=c[t[0]-'a'].get(0),j;
        for(i=1;i<t.length;i++)
        {
            int cc=t[i]-'a';
            j=binarys(c[cc],cur);
            if(j==c[cc].size())
            {
                ans++;
                cur=c[cc].get(0);
            }
            else cur=c[cc].get(j);
        }
        System.out.print(ans);
    }

    static int binarys(ArrayList<Integer> al,int k)
    {
        int l=0,r=al.size()-1,ans=r+1,mid;
        while(l<=r)
        {
            mid=(l+r)/2;
            if(al.get(mid)>k)
            {
                ans=mid;
                r=mid-1;
            }
            else l=mid+1;
        }
        return ans;
    }
}


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

public class Codeforces
{
    public static void main(String args[])throws Exception
    {
        BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb=new StringBuilder();
        char s[]=bu.readLine().toCharArray();
        char t[]=bu.readLine().toCharArray();
        ArrayList<Integer> c[]=new ArrayList[26];
        int i,ans=0,cn[]=new int[26];
        for(i=0;i<26;i++)
        c[i]=new ArrayList<>();

        for(i=0;i<s.length;i++)
        c[s[i]-'a'].add(i);

        for(i=0;i<t.length;i++)
        cn[t[i]-'a']++;

        boolean pos=true;
        for(i=0;i<26;i++)
        if(cn[i]!=0 && c[i].size()==0) {pos=false; break;}
        if(!pos) {System.out.print("-1"); return;}

        ans=1;
        int cur=c[t[0]-'a'].get(0),j;
        for(i=1;i<t.length;i++)
        {
            boolean f=false; int cc=t[i]-'a';
            for(j=0;j<c[cc].size();j++)
            if(c[cc].get(j)>cur)
            {
                cur=c[cc].get(j);
                f=true; break;
            }
            if(!f)
            {
                ans++;
                cur=c[cc].get(0);
            }
        }
        System.out.print(ans);
    }
}


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

public class Main
{

    public static void process()throws IOException
    {
        char s1[]=(" "+nln()).toCharArray(),s2[]=(" "+nln()).toCharArray();

        int len1=s1.length-1,len2=s2.length-1;

        TreeSet<Integer> l[]=new TreeSet[300];
        for(int i=0;i<300;i++) l[i]=new TreeSet<>();

        for(int i=1;i<=len1;i++)
            l[s1[i]].add(i);

        int res=1,curr=0;

        for(int i=1;i<=len2;i++){

            if(l[s2[i]].isEmpty()){
                pn(-1);
                return;
            }

            Integer nxt=l[s2[i]].higher(curr);

            if(nxt==null){
                res++;
                nxt=l[s2[i]].first();
            }

            curr=nxt;
        }
        pn(res);
    }

    static AnotherReader sc;
    static PrintWriter out;
    public static void main(String[]args)throws IOException
    {
        out = new PrintWriter(System.out);
        sc=new AnotherReader();
        boolean oj = true;

    	oj = System.getProperty("ONLINE_JUDGE") != null;
    	if(!oj) sc=new AnotherReader(100);

        long s = System.currentTimeMillis();
        int t=1;
		//t=ni();
        while(t-->0)
            process();
        out.flush();
        if(!oj)
            System.out.println(System.currentTimeMillis()-s+"ms");
        System.out.close();
    }

    static void pn(Object o){out.println(o);}
    static void p(Object o){out.print(o);}
    static void pni(Object o){out.println(o);System.out.flush();}
    static int ni()throws IOException{return sc.nextInt();}
    static long nl()throws IOException{return sc.nextLong();}
    static double nd()throws IOException{return sc.nextDouble();}
    static String nln()throws IOException{return sc.nextLine();}
    static long gcd(long a, long b)throws IOException{return (b==0)?a:gcd(b,a%b);}
    static int gcd(int a, int b)throws IOException{return (b==0)?a:gcd(b,a%b);}
    static int bit(long n)throws IOException{return (n==0)?0:(1+bit(n&(n-1)));}
    static boolean multipleTC=false;
    static long mod=(long)1e9+7l;

    static void r_sort(int arr[],int n){
        Random r = new Random();
        for (int i = n-1; i > 0; i--){
            int j = r.nextInt(i+1);

            int temp = arr[i];
            arr[i] = arr[j];
            arr[j] = temp;
        }
        Arrays.sort(arr);
    }

    static long mpow(long x, long n) {
        if(n == 0)
            return 1;
        if(n % 2 == 0) {
            long root = mpow(x, n / 2);
            return root * root % mod;
        }else {
            return x * mpow(x, n - 1) % mod;
        }
    }

    static long mcomb(long a, long b) {
        if(b > a - b)
            return mcomb(a, a - b);
        long m = 1;
        long d = 1;
        long i;
        for(i = 0; i < b; i++) {
            m *= (a - i);
            m %= mod;
            d *= (i + 1);
            d %= mod;
        }
        long ans = m * mpow(d, mod - 2) % mod;
        return ans;
    }
/////////////////////////////////////////////////////////////////////////////////////////////////////////

    static class AnotherReader{BufferedReader br; StringTokenizer st;
    AnotherReader()throws FileNotFoundException{
    br=new BufferedReader(new InputStreamReader(System.in));}
    AnotherReader(int a)throws FileNotFoundException{
    br = new BufferedReader(new FileReader("input.txt"));}
    String next()throws IOException{
    while (st == null || !st.hasMoreElements()) {try{
    st = new StringTokenizer(br.readLine());}
    catch (IOException  e){ e.printStackTrace(); }}
    return st.nextToken(); } int nextInt() throws IOException{
    return Integer.parseInt(next());}
    long nextLong() throws IOException
    {return Long.parseLong(next());}
    double nextDouble()throws IOException { return Double.parseDouble(next()); }
    String nextLine() throws IOException{ String str = ""; try{
    str = br.readLine();} catch (IOException e){
    e.printStackTrace();} return str;}}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
}


#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define foru(i, a, n) for (ll i = (a); i <= (n); ++i)
#define ford(i, n, a) for (ll i = (n); i >= (a); --i)
using namespace std;
typedef pair<int, int> ii;
const int inf = 1e9 + 7;
const int N = 2020;
ll m, n, k, ans = 0;
string s1, s2;
vector<int> a[255];

int main()
{
    //freopen((NAME + ".inp").c_str(), "r", stdin);
    //freopen((NAME + ".out").c_str(), "w", stdout);
    ios::sync_with_stdio(0);
    cin >> s1 >> s2;
    for (int i = 0; i < s1.size(); i++)
        a[s1[i]].push_back(i);

    int pos = 0, dem = 1;
    for (int i = 0; i < s2.size(); i++)
    {
        if (a[s2[i]].size() == 0)
            return cout << -1, 0;
        auto it = upper_bound(a[s2[i]].begin(), a[s2[i]].end(), pos);
        if (it == a[s2[i]].end())
            pos = 0, dem++;
        else
            pos = *it;
    }
    cout << dem;
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define foru(i, a, n) for (ll i = (a); i <= (n); ++i)
#define ford(i, n, a) for (ll i = (n); i >= (a); --i)
using namespace std;
typedef pair<int, int> ii;
const string NAME = "STRNEWS";
const int inf = 1e9 + 7;
const int N = 2020;
ll m, n, k, ans = 0;
string s1, s2;
vector<int> a[255];

int main()
{
    //freopen((NAME + ".inp").c_str(), "r", stdin);
    //freopen((NAME + ".out").c_str(), "w", stdout);
    ios::sync_with_stdio(0);
    cin >> s1 >> s2;
    for (int i = 0; i < s1.size(); i++)
        a[s1[i]].push_back(i);

    int pos = 0, dem = 0;
    for (int i = 0; i < s2.size(); i++)
    {
        if (a[s2[i]].size() == 0)
            return cout << -1, 0;
        auto it = lower_bound(a[s2[i]].begin(), a[s2[i]].end());
        if (it == a[s2[i]].end())

            pos = 0, dem++;
        else
            pos = *it;
    }
    cout << dem;
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define foru(i, a, n) for (ll i = (a); i <= (n); ++i)
#define ford(i, n, a) for (ll i = (n); i >= (a); --i)
using namespace std;
typedef pair<int, int> ii;
const int inf = 1e9 + 7;
const int N = 2020;
ll m, n, k, ans = 0;
string s1, s2;
set<char> dig;

int main()
{
    //freopen((NAME + ".inp").c_str(), "r", stdin);
    //freopen((NAME + ".out").c_str(), "w", stdout);
    ios::sync_with_stdio(0);
    cin >> s1 >> s2;
    for (auto x : s1)
        dig.insert(x);
    for (auto x : s2)
        if (dig.count(x) == 0)
            return cout << -1, 0;
    int j = 0, dem = 0;
    while (j < s2.size())
    {
        dem++;
        for (auto x : s1)
            if (j < s2.size() && s2[j] == x)
                j++;
    }
    cout << dem;
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define foru(i, a, n) for (ll i = (a); i <= (n); ++i)
#define ford(i, n, a) for (ll i = (n); i >= (a); --i)
using namespace std;
typedef pair<int, int> ii;
const int inf = 1e9 + 7;
const int N = 2020;
ll m, n, k, ans = 0;
string s1, s2;
vector<int> a[255];

int main()
{
    //freopen((NAME + ".inp").c_str(), "r", stdin);
    //freopen((NAME + ".out").c_str(), "w", stdout);
    ios::sync_with_stdio(0);
    cin >> s1 >> s2;
    for (int i = 0; i < s1.size(); i++)
        a[s1[i]].push_back(i);

    int pos = -1, dem = 1;
    for (int i = 0; i < s2.size(); i++)
    {
        if (a[s2[i]].size() == 0)
            return cout << -1, 0;
        auto it = upper_bound(a[s2[i]].begin(), a[s2[i]].end(), pos);
        if (it == a[s2[i]].end())
            pos = a[s2[i]][0], dem++;
        else
            pos = *it;
    }
    cout << dem;
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define foru(i, a, n) for (ll i = (a); i <= (n); ++i)
#define ford(i, n, a) for (ll i = (n); i >= (a); --i)
using namespace std;
typedef pair<int, int> ii;
const int inf = 1e9 + 7;
const int N = 2020;
ll m, n, k, ans = 0;
string s1, s2;
vector<int> a[255];

int main()
{
    //freopen((NAME + ".inp").c_str(), "r", stdin);
    //freopen((NAME + ".out").c_str(), "w", stdout);
    ios::sync_with_stdio(0);
    cin >> s1 >> s2;
    for (int i = 0; i < s1.size(); i++)
        a[s1[i]].push_back(i);

    int pos = 0, dem = 1;
    for (int i = 0; i < s2.size(); i++)
    {
        if (a[s2[i]].size() == 0)
            return cout << -1, 0;
        auto it = upper_bound(a[s2[i]].begin(), a[s2[i]].end(), pos);
        if (it == a[s2[i]].end())
            pos = a[s2[i]][0], dem++;
        else
            pos = *it;
    }
    cout << dem;
    return 0;
}


#include<bits/stdc++.h>
//define
#define fast ios::sync_with_stdio(0);cin.tie(0);ios_base::sync_with_stdio(0);
#define file  freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define ll long long
#define ld  double
#define mod 1000000007
using namespace std;

int main(){
    fast
    string s1,s2;
    cin>>s1>>s2;
    ll r= 1;
    set<char>st;
    for (char c : s1) {
        st.insert(c);
    }
    for(char c : s2){
        if(st.find(c) == st.end()){
            return cout<<-1,0;
        }
    }
    vector<vector<int>>m(s1.size(),vector<int>(26,-1));
    m.back()[s1[s1.size()-1]-'a']=0;
    for (int i = s1.size()-2; i >=0 ; --i) {
        for (int k = 0; k < 26; ++k) {
            if(m[i+1][k] != -1){
                m[i][k]=m[i+1][k]+1;
            }
            if(k == (int)(s1[i]-'a') ){
               m[i][k]=0;
            }
        }
    }
    ll j = 0;
    for (int i = 0; i < s2.size(); ++i) {
        if(m[j][s2[i]-'a'] == -1){
            j = m[0][s2[i]-'a']+1;
            if(j == s1.size()){
                j = 0;
                if(i != s2.size()-1)
                    r++;
            }
            r++;
        }else{
            j += m[j][s2[i]-'a']+1;
            if(j == s1.size()){
                j = 0;
                if(i != s2.size()-1)
                    r++;
            }
        }
    }
    cout<<r;
    return 0;
}


#include<bits/stdc++.h>
//define
#define fast ios::sync_with_stdio(0);cin.tie(0);ios_base::sync_with_stdio(0);
#define file  freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define ll long long
#define ld  double
#define mod 1000000007
using namespace std;

int main(){
    fast
    string s1,s2;
    cin>>s1>>s2;
    ll j = 0;
    ll r= 1;
    set<char>st;
    for (char c : s1) {
        st.insert(c);
    }
    for(char c : s2){
        if(st.find(c) == st.end()){
            return cout<<-1,0;
        }
    }
    for (int i = 0; i < s2.size(); ++i) {
        ll k ;
        if(k = s1.find(s2[i],j) == string::npos){
            r++;
            j = s1.find(s2[i],0)+1;
            if(j == s1.size())
                j=0;
        }else{
            j = k+1;
            if(j == s1.size())
                j=0;
        }
    }
    cout<<r;
    return 0;
}


#include<bits/stdc++.h>
//define
#define fast ios::sync_with_stdio(0);cin.tie(0);ios_base::sync_with_stdio(0);
#define file  freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define ll long long
#define ld  double
#define mod 1000000007
using namespace std;

int main(){
    fast
    string s1,s2;
    cin>>s1>>s2;
    ll j = 0;
    ll r= 1;
    set<char>st;
    for (char c : s1) {
        st.insert(c);
    }
    for(char c : s2){
        if(st.find(c) == st.end()){
            return cout<<-1,0;
        }
    }
    for (int i = 0; i < s2.size(); ++i) {
        ll k ;
        if(k = s1.find(s2[i],j) == string::npos){
            r++;
            j = s1.find(s2[i],0);
        }else{
            j = k+1;
            if(j == s1.size())
                j=0;
        }
    }
    cout<<r;
    return 0;
}


#include<bits/stdc++.h>
//define
#define fast ios::sync_with_stdio(0);cin.tie(0);ios_base::sync_with_stdio(0);
#define file  freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define ll long long
#define ld  double
#define mod 1000000007
using namespace std;

int main(){
    fast
    string s1,s2;
    cin>>s1>>s2;
    ll j = 0;
    ll r= 1;
    set<char>st;
    for (char c : s1) {
        st.insert(c);
    }
    for(char c : s2){
        if(st.find(c) == st.end()){
            return cout<<-1,0;
        }
    }
    for (int i = 0; i < s2.size(); ++i) {
        ll k ;
        if(k = s1.find(s2[i],j) == string::npos){
            r++;
            j = s1.find(s2[i],0)+1;
        }else{
            j = k+1;
            if(j == s1.size())
                j=0;
        }
    }
    cout<<r;
    return 0;
}


#include<bits/stdc++.h>
//define
#define fast ios::sync_with_stdio(0);cin.tie(0);ios_base::sync_with_stdio(0);
#define file  freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define ll long long
#define ld  double
#define mod 1000000007
using namespace std;

int main(){
    fast
    string s1,s2;
    cin>>s1>>s2;
    ll j = 0;
    ll r= 1;
    set<char>st;
    for (char c : s1) {
        st.insert(c);
    }
    for(char c : s2){
        if(st.find(c) == st.end()){
            return cout<<-1,0;
        }
    }
    for (int i = 0; i < s2.size(); ++i) {
        ll k;
        if( (k = s1.find(s2[i],j)) == string::npos){
            r++;
            j = s1.find(s2[i],0)+1;
            if(j == s1.size()){
                j=0;
                if(i != s2.size()-1)
                r++;
            }
        }else{
            j = k+1;
            if(j == s1.size()){
                j=0;
                if(i != s2.size()-1)
                r++;
            }
        }
    }
    cout<<r;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("Ofast")
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back

#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> vi;
typedef long long ll;
typedef pair<int,int> pii;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
#define w(x)            int x; cin>>x; while(x--)
#define FASTIO std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);

int main(){
FASTIO;

string a,b;
cin>>a;
cin>>b;
int n1 = a.size();
int n2 = b.size();
unordered_map<char,set<int> > mp;
for(int i=0;i<n1;i++)
{
   mp[a[i]].insert(i);
}

int count = 1 ;
int last = 0;
for(auto x:b)
{
    if(mp.find(x)==mp.end())
    {
        cout<<-1;
        return 0;
    }

   auto ls = lower_bound(mp[x].begin(), mp[x].end(),last);
   if(ls==mp[x].end())
  { count++;
  last = 0;}

   else
   last = *ls;

}
cout<<count<<endl;

return 0;
}


#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("Ofast")
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back

#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> vi;
typedef long long ll;
typedef pair<int,int> pii;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
#define w(x)            int x; cin>>x; while(x--)
#define FASTIO std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);

int main(){
FASTIO;

string a,b;
cin>>a;
cin>>b;
int n1 = a.size();
int n2 = b.size();
unordered_map<char,set<int> > mp;
for(int i=0;i<n1;i++)
{
   mp[a[i]].insert(i);
}

int count = 1 ;
int last = 0;
for(auto x:b)
{
    if(mp.find(x)==mp.end())
    {
        cout<<-1;
        return 0;
    }

   auto ls = upper_bound(mp[x].begin(), mp[x].end(),last);
   if(ls==mp[x].end())
  { count++;
  last = 0;}

   else
   last = *ls;

}
cout<<count<<endl;

return 0;
}


#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("Ofast")
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back

#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> vi;
typedef long long ll;
typedef pair<int,int> pii;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
#define w(x)            int x; cin>>x; while(x--)
#define FASTIO std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);

int main(){
FASTIO;

string a,b;
cin>>a;
cin>>b;
int n1 = a.size();
int n2 = b.size();
unordered_map<int,vi > mp;
for(int i=0;i<n1;i++)
{
   mp[a[i]-'a'].pb(i+1);
}

int count = 1 ;
int last = 0;
for( int i=0;i<n2;i++)
{int x = b[i]-'a';
    if(mp.find(x)==mp.end())
    {
        cout<<-1;
        return 0;
    }

   auto ls = upper_bound(mp[x].begin(), mp[x].end(),last);
   if(ls==mp[x].end())
  { count++;
  last = 0;
  i--;
  }

   else
   last = *ls;

}
cout<<count<<endl;

return 0;
}


#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("Ofast")
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back

#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> vi;
typedef long long ll;
typedef pair<int,int> pii;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
#define w(x)            int x; cin>>x; while(x--)
#define FASTIO std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);

int main(){
FASTIO;

string a,b;
cin>>a;
cin>>b;
int n1 = a.size();
int n2 = b.size();
unordered_map<char,set<int> > mp;
for(int i=0;i<n1;i++)
{
   mp[a[i]].insert(i+1);
}

int count = 1 ;
int last = 0;
for(auto x:b)
{
    if(mp.find(x)==mp.end())
    {
        cout<<-1;
        return 0;
    }

   auto ls = upper_bound(mp[x].begin(), mp[x].end(),last);
   if(ls==mp[x].end())
  { count++;
  last = *mp[x].begin();}

   else
   last = *ls;

}
cout<<count<<endl;

return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int MAXN = 1e6+7;
const int INF = 0x3f3f3f3f;
int vis[MAXN];
int vis1[100][1004];
int cnt[100];
vector<int> pos[200];
int main() {
    ios::sync_with_stdio(false);
    string s1,s2;
    cin >> s1 >> s2;
    //memset(pos,INF,sizeof(pos));
    int len1 = s1.size(),len2 = s2.size();
    for(int i = 0;i < len1;i++)
        vis[s1[i]] = 1;

    for(int i = 0;i < len1;i++){
        int t = s1[i];
        pos[t].push_back(i);
    }

    for(int i = 0;i < len2;i++){
        if(vis[s2[i]] == 0){
            cout << -1 << endl;
            return  0;
        }
    }
    int ans = 1;
    for(int j = 0,i = pos[s2[0]][0];j < len2;i = pos[s2[j]][cnt[s2[j]]]){
    	if(s2[j] == s1[i]){
    		cnt[s2[j]]++;
        	j++;
        	if(j == len2)
        		break;
		}
		if(cnt[s2[j]] == pos[s2[j]].size() || ((i+1)%len1 == 0)){
			memset(cnt,0,sizeof(cnt));
            ans++;
		}
    }
    cout << ans << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int MAXN = 1e6+7;
const int INF = 0x3f3f3f3f;
int vis[MAXN];
int pos[MAXN];
int main() {
    ios::sync_with_stdio(false);
    string s1,s2;
    cin >> s1 >> s2;
    memset(pos,INF,sizeof(pos));
    int len1 = s1.size(),len2 = s2.size();
    for(int i = 0;i < len1;i++)
        vis[s1[i]] = 1;
    for(int i = 0;i < len1;i++){
        pos[s1[i]] = min(i,pos[s1[i]]);
    }
    int ans = 1;
    for(int j = 0,i = pos[s2[0]];j < len2;i = pos[s2[j]]){
    	if(s2[j] == s1[i]){
        	j++;
		}
    	if((i+1)%len1 == 0){
			ans++;
			j++;
		}
    }
    for(int i = 0;i < len2;i++){
        if(vis[s2[i]] == 0){
            cout << -1 << endl;
            return  0;
        }

    }
    cout << ans << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int MAXN = 1e6+7;
const int INF = 0x3f3f3f3f;
set<int> S[30];
int main() {
    ios::sync_with_stdio(false);
    string s1,s2;
    cin >> s1 >> s2;
    int len1 = s1.size(),len2 = s2.size(),last = -1,ans = 0;
    for(int i = 0;i < len1;i++){
        int pos = s1[i] - 'a';
        S[pos].insert(i);
    }
    for(int i = 0;i < len2;i++){
        int pos = s2[i] - 'a';
        if(S[pos].empty()){
            cout << -1 <<endl;
            return 0;
        }
        set<int>::iterator it = S[pos].upper_bound(last);
        if(it == S[pos].end()){
            ans++;
            last = -1;
        }
        last = *S[pos].upper_bound(last);
    }
    cout << ans+1 << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int MAXN = 1e6+7;
const int INF = 0x3f3f3f3f;
int vis[MAXN];
int vis1[100][1004];
int cnt[100];
vector<int> pos[200];
int main() {
    ios::sync_with_stdio(false);
    string s1,s2;
    cin >> s1 >> s2;
    //memset(pos,INF,sizeof(pos));
    int len1 = s1.size(),len2 = s2.size();
    for(int i = 0;i < len1;i++)
        vis[s1[i]] = 1;

    for(int i = 0;i < len1;i++){
        int t = s1[i];
        pos[t].push_back(i);
    }

    for(int i = 0;i < len2;i++){
        if(vis[s2[i]] == 0){
            cout << -1 << endl;
            return  0;
        }
    }
    int ans = 1;
    for(int j = 0,i = pos[s2[0]][0];j < len2;i = pos[s2[j]][cnt[s2[j]]]){
		cnt[s2[j]]++;
    	j++;
    	if(j == len2)
    		break;
		if(cnt[s2[j]] == pos[s2[j]].size() || ((i+1)%len1 == 0)){
			memset(cnt,0,sizeof(cnt));
            ans++;
		}
    }
    cout << ans << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int MAXN = 1e6+7;
const int INF = 0x3f3f3f3f;
int vis[MAXN];
int pos[MAXN];
int main() {
    ios::sync_with_stdio(false);
    string s1,s2;
    cin >> s1 >> s2;
    memset(pos,INF,sizeof(pos));
    int len1 = s1.size(),len2 = s2.size();
    for(int i = 0;i < len1;i++)
        vis[s1[i]] = 1;
    for(int i = 0;i < len1;i++){
        pos[s1[i]] = min(i,pos[s1[i]]);
    }
    for(int i = 0;i < len2;i++){
        if(vis[s2[i]] == 0){
            cout << -1 << endl;
            return  0;
        }
    }
    int ans = 1;
    for(int j = 0,i = pos[s2[0]];j < len2;i = pos[s2[j]]){
    	if(s2[j] == s1[i]){
        	j++;
		}
    	if((i+1)%len1 == 0){
			ans++;
			j++;
		}
    }
    cout << ans << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int MAXN = 1e6+7;
const int INF = 0x3f3f3f3f;
int vis[MAXN];
int pos[MAXN];
int main() {
    ios::sync_with_stdio(false);
    string s1,s2;
    cin >> s1 >> s2;
    memset(pos,INF,sizeof(pos));
    int len1 = s1.size(),len2 = s2.size();
    for(int i = 0;i < len1;i++)
        vis[s1[i]] = 1;
    for(int i = 0;i < len1;i++){
        pos[s1[i]] = min(i,pos[s1[i]]);
    }
    for(int i = 0;i < len2;i++){
        if(vis[s2[i]] == 0){
            cout << -1 << endl;
            return  0;
        }
    }
    int ans = 1;
    for(int i = 0,j = 0;j < len2;i = pos[s2[j]]){
    	if((i+1)%len1 == 0){
			ans++;
			j++;
			//i = pos[s2[j]] - 1;
			//j--;
		}
        if(s2[j] == s1[i]){
        	j++;
        	continue;
		}

    }
    cout << ans << endl;
    return 0;
}


  // @uthor :  _|EE|_RB30

#include<bits/stdc++.h>
using namespace std;

#define int long long

#define vi vector<int>
#define vpi vector<pair<int,int>>
#define pb push_back

#define pii pair<int,int>
#define mii map<int,int>
#define mpi map<pair<int,int>,int>

#define M 1000000007
#define pi 3.141592653589793238
#define endl "\n"
#define brisk ios_base::sync_with_stdio(false);cin.tie(NULL);

signed main()
{
     brisk;
     string s,t;
     cin>>s>>t;
     mii mm;
     int c = 0;

     for(int i=0;i<s.length();i++){
          mm[s[i]-'a']++;
     }

     for(int i=0;i<t.length();i++){
          if(!mm[t[i]-'a']){
               c++;
               break;
          }
     }

     if(c)cout<<"-1";
     else{
          int i = 0, j = 0, ans = 0;

          while(j<t.length()){
               if(i==s.length()){
                    i = 0;
                    ans++;
               }
               if(s[i]==t[j]){
                    i++;
                    j++;
               }else i++;
          }

          cout<<ans+1<<endl;
     }

}


  // @uthor :  _|EE|_RB30

#include<bits/stdc++.h>
using namespace std;

#define int long long

#define vi vector<int>
#define vpi vector<pair<int,int>>
#define pb push_back

#define pii pair<int,int>
#define mii map<int,int>
#define mpi map<pair<int,int>,int>

#define M 1000000007
#define pi 3.141592653589793238
#define endl "\n"
#define brisk ios_base::sync_with_stdio(false);cin.tie(NULL);

signed main()
{
     brisk;
     string s,t;
     cin>>s>>t;

     int n = s.length();
     vector<vector<int>> dp(n+1,vector<int>(26,-1));

     for(int i=n-1;i>=0;i--){
          for(char j='a';j<='z';j++){
               if(s[i]==j)dp[i][j-'a'] = i;
               else if(i+1<=n)dp[i][j-'a'] = dp[i+1][j-'a'];
          }
     }

     int pos = 0, ans = 1;

     for(int i=0;i<t.length();i++){
          int p = dp[pos][t[i]-'a'];
          if(p==-1){
               ans++;
               pos = 0;
               p = dp[pos][t[i]-'a'];
               if(p==-1){
                    ans = -1;
                    break;
               }
          }else pos = p;
          pos++;
     }

     cout<<ans;
}


  // @uthor :  _|EE|_RB30

#include<bits/stdc++.h>
using namespace std;

#define int long long

#define vi vector<int>
#define vpi vector<pair<int,int>>
#define pb push_back

#define pii pair<int,int>
#define mii map<int,int>
#define mpi map<pair<int,int>,int>

#define M 1000000007
#define pi 3.141592653589793238
#define endl "\n"
#define brisk ios_base::sync_with_stdio(false);cin.tie(NULL);

signed main()
{
     brisk;
     string s,t;
     cin>>s>>t;

     int n = s.length();
     vector<vector<int>> dp(n+1,vector<int>(26,-1));

     for(int i=n-1;i>=0;i--){
          for(char j='a';j<='z';j++){
               if(s[i]==j)dp[i][j-'a'] = i;
               else if(i+1<=n)dp[i][j-'a'] = dp[i+1][j-'a'];
          }
     }

     int pos = 0, ans = 1;

     for(int i=0;i<t.length();i++){
          int p = dp[pos][t[i]-'a'];
          if(p==-1){
               ans++;
               pos = 0;
               p = dp[pos][t[i]-'a'];
               if(p==-1){
                    ans = -1;
                    break;
               }
               pos = p;
          }else pos = p;
          pos++;
     }

     cout<<ans;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
int tt;
int tot;
const int maxn = 2e6 + 5;
int T;
char s[maxn];
int now[31];//记录字母最早出现的位置
char t[maxn];
int nex[maxn][30];//nex[i][j]记录在主串第i个字符之后（'a'+j)第一次出现的位置
void init() {
    memset(now,-1,sizeof(now));
    int len  = strlen(s + 1);
    for(int i = len; i >= 0; i--) {
        for(int j = 0; j < 26; j++) {
            nex[i][j] = now[j];//初始now[]均为-1，在主串最后一个字符，在主串最后一个字符没有字符了
        }
        if(i)
            now[s[i] - 'a'] = i;//不断更新，记录字母最早出现的位置
    }
}

void solve(){
	scanf("%s%s",s+1,t+1);
	init();
        int pos = 0;
        int ans = 1;
        bool f = 0;
        int len = strlen(t + 1);
        for(int i = 1; i <= len; i++) {
            int r = t[i] - 'a';
            if(nex[pos][r] == -1) {
                if(nex[0][r] == -1) {
                    f = 1;
                    break;
                }
                ans++;
                pos = 0;
            }
            pos = nex[pos][r];
        }
        if(f == 1) {
            ans = -1;
        }
        printf("%d\n",ans);
}

int main(){

    tt = 1;
    tot = 0;
	while(tt--){
    	solve();
	}

}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
int tt;
int tot;
const int maxn = 2e6 + 5;
int T;
char s[maxn];
int now[30];//记录字母最早出现的位置
char t[maxn];
int nex[maxn][30];//nex[i][j]记录在主串第i个字符之后（'a'+j)第一次出现的位置
void init() {
    memset(now,-1,sizeof(now));
    int len  = strlen(s + 1);
    for(int i = len; i >= 0; i--) {
        for(int j = 0; j < 26; j++) {
            nex[i][j] = now[j];//初始now[]均为-1，在主串最后一个字符，在主串最后一个字符没有字符了
        }
        if(i)
            now[s[i] - 'a'] = i;//不断更新，记录字母最早出现的位置
    }
}

void solve(){
	scanf("%s%s",s+1,t+1);
	init();
        int pos = 0;
        int ans = 1;
        bool f = 0;
        int len = strlen(t + 1);
        for(int i = 1; i <= len; i++) {
            int r = t[i] - 'a';
            if(nex[pos][r] == -1) {
                if(nex[0][r] == -1) {
                    f = 1;
                    break;
                }
                ans++;
                pos = 0;
            }
            pos = nex[pos][r];
        }
        if(f == 1) {
            ans = -1;
        }
        printf("%d\n",ans);
}

int main(){

    tt = 1;
    tot = 0;
	while(tt--){
    	solve();
	}

}


/* BISMILLAHIR RAHMANIR RAHIM */
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define mod 1000000007
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;
const int nnn = 1e6+10;
char sss[nnn], ttt[nnn];
int ami[nnn][28];
int main(){
    cin>>sss;
    cin>>ttt;
    int n = strlen(sss);
    for(int i = n; i<n+n; i++) sss[i] = sss[i-n];

    for(int c = 0; c<26; c++)
	ami[2*n][c] = -1;
    for(int i = 2*n-1; i>=0; i--){
        for(int c = 0; c<26; c++)
            ami[i][c] = ami[i+1][c];
        ami[i][sss[i]-'a'] = i;
    }
    int ans = 0;
    for(int i = 0, j = n-1; ttt[i] != 0; i++){
        int c = ttt[i]-'a';
        if(ami[j+1][c] == -1){
            ans = -1;
            break;
        }
        j = ami[j+1][c];
        if(j >= n)
		ans++, j-=n;
    }

    cout<<ans<<endl;
    return 0;
}


/* BISMILLAHIR RAHMANIR RAHIM */
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define mod 1000000007
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;
const int nnn = 1e6+10;
char sss[nnn], ttt[nnn];
int ami[nnn][28];
int main(){
    IOS;
    cin>>sss;
    cin>>ttt;
    int n = strlen(sss);
    for(int i = n; i<n+n; i++) sss[i] = sss[i-n];

    for(int c = 0; c<26; c++)
	ami[2*n][c] = -1;
    for(int i = 2*n-1; i>=0; i--){
        for(int c = 0; c<26; c++)
            ami[i][c] = ami[i+1][c];
        ami[i][sss[i]-'a'] = i;
    }
    int ans = 0;
    for(int i = 0, j = n-1; ttt[i] != 0; i++){
        int c = ttt[i]-'a';
        if(ami[j+1][c] == -1){
            ans = -1;
            break;
        }
        j = ami[j+1][c];
        if(j >= n)
		ans++; j-=n;
    }

    cout<<ans<<endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using pii = pair<int, int>;

void solve() {
	//~ freopen("lca.out", "w", stdout);
	//~ freopen("lca.in", "r", stdin);
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);

	string s1, s2;
	cin >> s1 >> s2;
	vector<int> ltrs1(26, 0), ltrs2(26, 0);
	for (char c : s1)
		ltrs1[c - 'a']++;
	for (char c : s2)
		ltrs2[c - 'a']++;
	for (int i = 0; i < 26; i++) {
		int a = ltrs1[i];
		int b = ltrs2[i];
		if (b == 0)
			continue;
		if (a == 0) {
			cout << -1;
			return;
		}
	}

	int ans = 1;
	int l = 0;
	int r = 0;
	while (l < s2.size()) {
		while (s1[r] != s2[l]) {
			r++;
			if (r == s1.size()) {
				r = 0;
				ans++;
			}
		}
		r++;
		l++;
	}

	cout << ans;
}

int main() {
	solve();
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using pii = pair<int, int>;

void solve() {
	//~ freopen("lca.out", "w", stdout);
	//~ freopen("lca.in", "r", stdin);
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);

	string s1, s2;
	cin >> s1 >> s2;
	vector<int> ltrs1(26, 0), ltrs2(26, 0);
	for (char c : s1)
		ltrs1[c - 'a']++;
	for (char c : s2)
		ltrs2[c - 'a']++;
	for (int i = 0; i < 26; i++) {
		int a = ltrs1[i];
		int b = ltrs2[i];
		if (b == 0)
			continue;
		if (a == 0) {
			cout << -1;
			return;
		}
	}

	int ans = 1;
	int l = 0;
	int r = 0;
	while (l < s2.size()) {
		while (s1[r] != s2[l]) {
			r++;
			if (r == s1.size()) {
				r = 0;
				ans++;
			}
		}
		r++;
		if (r == s1.size()) {
			r = 0;
			ans++;
		}
		l++;
	}

	cout << ans;
}

int main() {
	solve();
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using pii = pair<int, int>;

void solve() {
	//~ freopen("lca.out", "w", stdout);
	//~ freopen("lca.in", "r", stdin);
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);

	string s1, s2;
	cin >> s1 >> s2;
	vector<int> ltrs1(26, 0), ltrs2(26, 0);
	for (char c : s1)
		ltrs1[c - 'a']++;
	for (char c : s2)
		ltrs2[c - 'a']++;
	for (int i = 0; i < 26; i++) {
		int a = ltrs1[i];
		int b = ltrs2[i];
		if (b == 0)
			continue;
		if (a == 0) {
			cout << -1;
			return;
		}
	}
	vector<set<int>> idx(26);
	for (int i = 0; i < s1.size(); i++)
		idx[s1[i] - 'a'].insert(i);

	int ans = 1;
	int l = 0;
	int r = 0;
	while (l < s2.size()) {
		if (s1[r] != s2[l]) {
			auto itr = idx[s2[l] - 'a'].lower_bound(r);
			if (itr == idx[s2[l] - 'a'].end()) {
				ans++;
				itr = idx[s2[l] - 'a'].lower_bound(0);
			}
			r = *itr;
		}
		r++;
		l++;
		if (r == s1.size() && l < s2.size()) {
			r = 0;
			ans++;
		}
	}

	cout << ans;
}

int main() {
	solve();
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using pii = pair<int, int>;

void solve() {
	//~ freopen("lca.out", "w", stdout);
	//~ freopen("lca.in", "r", stdin);
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);

	string s1, s2;
	cin >> s1 >> s2;
	vector<int> ltrs1(26, 0), ltrs2(26, 0);
	for (char c : s1)
		ltrs1[c - 'a']++;
	for (char c : s2)
		ltrs2[c - 'a']++;
	for (int i = 0; i < 26; i++) {
		int a = ltrs1[i];
		int b = ltrs2[i];
		if (b == 0)
			continue;
		if (a == 0) {
			cout << -1;
			return;
		}
	}

	int ans = 1;
	int l = 0;
	int r = 0;
	while (l < s2.size()) {
		while (s1[r] != s2[l]) {
			r++;
			if (r == s1.size()) {
				r = 0;
				ans++;
			}
		}
		r++;
		l++;
		if (r == s1.size() && l < s2.size()) {
			r = 0;
			ans++;
		}
	}

	cout << ans;
}

int main() {
	solve();
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using pii = pair<int, int>;

void solve() {
	//~ freopen("lca.out", "w", stdout);
	//~ freopen("lca.in", "r", stdin);
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);

	string s1, s2;
	cin >> s1 >> s2;
	vector<int> ltrs1(26, 0), ltrs2(26, 0);
	for (char c : s1)
		ltrs1[c - 'a']++;
	for (char c : s2)
		ltrs2[c - 'a']++;
	for (int i = 0; i < 26; i++) {
		int a = ltrs1[i];
		int b = ltrs2[i];
		if (b == 0)
			continue;
		if (a == 0) {
			cout << -1;
			return;
		}
	}

	int ans = 1;
	int l = 0;
	int r = 0;
	while (l < s2.size()) {
		while (s1[r] != s2[l]) {
			r++;
			if (r == s1.size()) {
				r = 0;
				ans++;
			}
		}
		l++;
	}

	cout << ans;
}

int main() {
	solve();
	return 0;
}


#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize("-Ofast")
#include <bits/stdc++.h>
using namespace std;

typedef int in;
#define int long long
#define pb push_back
#define pf push_front
#define f first
#define s second
#define double long double
#define p push
const int MAX=2e5+5;
const int MAX2=1e6+5;
const int MAAX=2e12;
const int MOD=1e9+7;
vector<int>v[30];
in main()
{
   string s;
   cin>>s;
   string s2;
   cin>>s2;
   for(int i=0;i<s2.size();i++)
   {
       v[s2[i]-'a'].pb(i);
   }
   int ans=1;
   int cur=0;
   for(int i=0;i<s.size();i++)
   {
       int curl=s[i]-'a';
       int idx=lower_bound(v[curl].begin(),v[curl].end(),cur)-v[curl].begin();
       if(idx==v[curl].size())
       {
           ans++;
           cur=0;
          idx=lower_bound(v[curl].begin(),v[curl].end(),cur)-v[curl].begin();
          if(idx==v[curl].size())
          {
              cout<<-1<<endl;
              return 0;
          }
       }
       cur=v[curl][idx]+1;
   }
   cout<<ans<<endl;
  return 0;
}


#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize("-Ofast")
#include <bits/stdc++.h>
using namespace std;

typedef int in;
#define int long long
#define pb push_back
#define pf push_front
#define f first
#define s second
#define double long double
#define p push
const int MAX=2e5+5;
const int MAX2=1e6+5;
const int MAAX=2e12;
const int MOD=1e9+7;
vector<int>v[30];
in main()
{
   string s;
   cin>>s;
   string s2;
   cin>>s2;
   for(int i=0;i<s.size();i++)
   {
       v[s[i]-'a'].pb(i);
   }
   int ans=1;
   int cur=0;
   for(int i=0;i<s.size();i++)
   {
       int curl=s2[i]-'a';
       int idx=lower_bound(v[curl].begin(),v[curl].end(),cur)-v[curl].begin();
       if(idx==v[curl].size())
       {
           ans++;
           cur=0;
          idx=lower_bound(v[curl].begin(),v[curl].end(),cur)-v[curl].begin();
          if(idx==v[curl].size())
          {
              cout<<-1<<endl;
              return 0;
          }
       }
       cur=v[curl][idx]+1;
   }
   cout<<ans<<endl;
  return 0;
}


#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize("-Ofast")
#include <bits/stdc++.h>
using namespace std;

typedef int in;
#define int long long
#define pb push_back
#define pf push_front
#define f first
#define s second
#define double long double
#define p push
const int MAX=2e5+5;
const int MAX2=1e6+5;
const int MAAX=2e12;
const int MOD=1e9+7;
vector<int>v[30];
in main()
{
   string s;
   cin>>s;
   string s2;
   cin>>s2;
   for(int i=0;i<s.size();i++)
   {
       v[s[i]-'a'].pb(i);
   }
   int ans=1;
   int cur=0;
   for(int i=0;i<s2.size();i++)
   {
       int curl=s2[i]-'a';
       int idx=lower_bound(v[curl].begin(),v[curl].end(),cur)-v[curl].begin();
       if(idx==v[curl].size())
       {
           ans++;
           cur=0;
          idx=lower_bound(v[curl].begin(),v[curl].end(),cur)-v[curl].begin();
          if(idx==v[curl].size())
          {
              cout<<-1<<endl;
              return 0;
          }
       }
       cur=v[curl][idx]+1;
   }
   cout<<ans<<endl;
  return 0;
}