Burr and Erdős conjectured in 1976 that for every two integers k>ℓ⩾0 satisfying that kZ+ℓ contains an even integer, an n-vertex graph containing no cycles of length ℓ modulo k can contain at most a linear number of edges on n. Bollobás confirmed this conjecture in 1977 and then Erdős proposed the problem of determining the exact value of the maximum number of edges in such a graph. For the above k and ℓ, define cℓ,k to be the least constant such that every n-vertex graph with at least cℓ,k⋅n edges contains a cycle of length ℓ modulo k. The precise (or asymptotic) values of cℓ,k are known for very few pairs ℓ and k. In this paper, we precisely determine the maximum number of edges in a graph containing no cycles of length 1 modulo 3. In particular, we show that every n-vertex graph with at least 35(n−1) edges contains a cycle of length 1 modulo 3, unless 9∣(n−1) and each block of the graph is a Petersen graph. As a corollary, we obtain that c1,3=35. This is the last remaining class modulo k for 1⩽k⩽4.