I am trying to generate latex output as given below.

![enter image description here](https://i.stack.imgur.com/7ZJ6Q.png)

However, the types is not coming properly aligned.
It looks like it subscribes to the previous array environment.
Could you please point out the error?

My code is as follows - 

```
\documentclass{article}
\usepackage{amssymb,amsmath}

\def    \R      {\mathbb{R}}

\begin{document}

\begin{equation}
    M_2=\left\{ 
    \begin{array}{r}
    variables : \left\{ \begin{array}{r} 
    inputs : x \\
    outputs : y 
    \end{array}
    \right.\\
    types : x,y \in \R \\   
    behaviors :  y = e^x \\  
    \end{array}
    \right.
\end{equation}
\end{document}

```