m, n, m0, md, n0, nd = gets.split.map(&:to_i)

degs_l = [m0]
(m - 1).times do
    degs_l << (degs_l[-1] * 58 + md) % (n + 1)
end

degs_r = [n0]
(n - 1).times do
    degs_r << (degs_r[-1] * 58 + nd) % (m + 1)
end

degs_l.sort!
degs_r.sort!

k = 0
degs_l.each do |x|
    degs_r.reject! {|y| y == 0}
    x = [x, degs_r.size].min
    k += x
    (-x..-1).each {|i| degs_r[i] -= 1}
    degs_r.sort!
end

p k