Clear[a]

a[1] := 1

a[n_] := a[n - 1] + 3

Clear[M]

M[N_] := Module[{n = 1}, While[a[n] < N, n = n + 1]; n - 1]

M[100]