Appeal from a judgment of the County Court of Otsego County (Mogavero, Jr., J.), rendered June 10, 1985, convicting defendant upon his plea of guilty of the crimes of grand larceny in the second degree and petit larceny.
Defendant was charged with a total of 17 counts in two separate indictments. Pursuant to a plea bargain, defendant pleaded guilty to grand larceny in the second degree and petit larceny. Pursuant to that plea bargain, defendant was to be sentenced as a second felony offender to a prison term of IV2 to 3 years on the grand larceny charge. Sentencing on the petit larceny charge was to be postponed for three years or until defendant was released from imprisonment on the grand larceny charge. County Court thereafter sentenced defendant in strict accordance with this plea bargain.
With regard to the sentence imposed by County Court, we find that such sentence was unauthorized as a matter of law. The court adjudicated defendant a second felony offender. Having been so adjudicated, defendant should have been sentenced to, at the very least, a term of 2 to 4 years on the conviction for grand larceny in the second degree, a class D felony (see, Penal Law § 70.06 [2], [3] [d]; [4] [b]). Under the statute, County Court was powerless to impose the UA-to-3year term that was promised (see, People v Grant, 92 AD2d 985). Although this error was neither raised before County Court nor addressed in the brief of either party on appeal, this court cannot permit a sentence which is invalid as a matter of law to stand (see, CPL 470.15 [2] [c]; People v Gustafson, 101 AD2d 920, 921; People v Grant, supra). Accordingly, we reverse and remit the matter to County Court where defendant should be given the opportunity to withdraw his guilty plea and stand trial or, should he not choose that option, be resentenced in compliance with the statute (see, People v Grant, supra).
Judgment reversed, on the law, and matter remitted to the County Court of Otsego County for further proceedings not inconsistent herewith. Kane, J. P., Main, Casey, Mikoll and Yesawich, Jr., JJ., concur.