#ifdef LOCAL
#include ".debug.hpp"
#else
#define debug(...) 42
#endif
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
using ordered_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;
signed main() {
#ifndef VOID
cin.tie(nullptr)->sync_with_stdio(false);
#endif
int N, S; cin >> S >> N;
int64_t ans = 0;
vector<array<int64_t, 3>> A(N); for (auto &a : A) cin >> a[0] >> a[1] >> a[2];
int64_t low = 1, high = A[0][2], mid, best = 0;
while (low <= high) {
mid = (low + high) >> 1;
int64_t res = A[0][1] * mid;
if (res <= S) best = mid, low = mid + 1;
else high = mid - 1;
}
cout << best * A[0][0];
return 0;
}