#include <iostream>
using namespace std;
int main()
{
unsigned int n, m;
cout<<"n = "; cin>>n;
cout<<"m = "; cin>>m;
unsigned int a[n][m];
cout<<"Elementele din matrice sunt: "<<endl;
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
cin>>a[i][j];
cout<<"Elementele de pe marginile matricie sunt:"<<endl;
cout<<"Margine - sus "<<endl;
for(int j=0;j<m;j++)
cout<<a[0][j]<<" ";
cout<<endl<<"Margine - dreapta"<<endl;
for(int i=0;i<n;i++)
cout<<a[i][m-1]<<endl;
cout<<"Margine - jos"<<endl;
for(int j=0;j<m;j++)
cout<<a[n-1][j]<<" ";
cout<<endl<<"Margine - stanga"<<endl;
for(int i=0;i<n;i++)
cout<<a[i][0]<<endl;
}