#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <fstream>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <time.h>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) (min(a,b) <= (x) && (x) <= max(a,b)) //hei
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 1000000007LL
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589


#define izryt bool
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
	std::fill((T*)array, (T*)(array + N), val);
}
pll Dir[4] = {
	{ -1 ,0 },{ 0 , 1 },{ 1 ,0 },{ 0 ,-1 }
};

//[a, b)
#define Getsum(ar, a,b) (ar[b] - ar[a])
#define chmax(a,b) a = max(a,b)
#define chmin(a,b) a = min(a,b)

struct Edge {
	int from, to;
	ll w;
	bool operator<(const Edge& rhs) const {
		return MP(w, MP(from, to)) < MP(rhs.w, MP(rhs.from, rhs.to));
	}

};
typedef vector<vector<Edge>> Graph;

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

ll factorial(ll n) {//階乗
	ll ret = 1;
	rep(i, 1, n + 1)
		ret = (ret *i) % MODU;

	return ret;
}

ll mod_pow(ll x, ll n, ll mod) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x %mod;
		x = x * x%mod;
		n >>= 1;
	}
	return res;
}
ll divmod(ll a, ll b, ll m) { // a/b(mod m)
								  // a/b (mod m)
								  // a*b^-1
								  // b^-1 * b = 1
								  // b^(m-1) = 1 
								  // b^(m-2) * b = 1
								  // b^-1 = b^(m-2)

								  // a/b = a * b^(m-2)

	return (a * 1LL * mod_pow(b, m - 2, m)) % m;
}
ll ncr(ll n, ll r) {
	return divmod(factorial(n), (factorial(r) * (factorial(n - r))) % MODU, MODU);
}

int n;
string base;
bool quest(int from) { //True:base
	printf("?");
	REP(i, n) {
		printf(" %d", (from+ i) % (2*n) + 1);
	}
	cout << endl;
	string str;
	cin >> str;
	return str == base;
}

bool quest(int from, int ad) { //True:base
	printf("?");
	REP(i, n - 1) {
		printf(" %d", (from + i) % (2 * n) + 1);
	}
	printf(" %d", ad + 1);
	
	cout << endl;
	string str;
	cin >> str;
	return str == base;
}


array<int, 3> c[100001] = {};
int cc[100001] = {};
signed main() {
	ll t1, t2,a1,a2,b1,b2;
	cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;

	if (a1*t1 + a2 * t2 < b1*t1 + b2 * t2) {
		swap(a1,b1);
		swap(a2, b2);
	}
	ll l1 = a1*t1 + a2*t2, l2 = b1*t1 + b2*t2;
	if (l1 == l2) {
		cout << "infinity" << endl;
		return 0;
	}
	ll dl = l1 - l2;

	int st[3] = {};// da,db,dc 0->0 1->pos 2->nega
	ll stl[3] = {};
	stl[0] = 0;
	stl[1] = a1 * t1 - b1 * t1;
	stl[2] = l1 - l2;

	st[0] = 0;
	st[2] = 1;
	if (stl[1] == 0) {
		st[1] = 0;
	}
	if (stl[1] > 0) {
		st[1] = 1;
	}
	if (stl[1] < 0) {
		st[1] = 2;
	}
	
	set<ll> ts;
	REP(i, 3) {
		if(st[i] == 0)
			ts.insert(1);
		if (st[i] == 2) {
			if (stl[i] % dl == 0) ts.insert(-stl[i] / dl);
			ts.insert(-stl[i] / dl + 1);
		}
	}
	ll ans = 0;

	ll bef = 0;
	int cst[3] = {st[0],st[1],st[2]};
	
	for (ll t : ts) {

		REP(i, 3) {
			cst[i] = (cst[i] < 2);
		}
		ans += (t - 1 - bef) * (cst[0] != cst[1]);
		ans += (t - 1 - bef) * (cst[1] != cst[2]);

		ll ctl[3] = {};
		REP(i, 3) {
			ctl[i] = stl[i] + dl * t;
			if(ctl[i] == 0)
				cst[i] = 0;
			if (ctl[i] > 0)
				cst[i] = 1;
			if (ctl[i] < 0)
				cst[i] = 2;
		}
		ans += (cst[0] != cst[1]);
		ans += (cst[1] != cst[2]);
		if (cst[1] == 0) ans--;
		bef = t;
	}
	ans += st[1] != st[2];
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256