Mr. Carter served as U.S. president from 1977 to 1981 .