#include<bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<(int)N;i++)
int main()
{
  int N,M,a=0,x;
  cin>>N>>M;
  vector<int> c(M),s(M),used(3,0);
  rep(i,M)
  {
    cin>>s.at(i)>>c.at(i);
    if(used.at(s.at(i)-1)=!0&&used.at(s.at(i)-1)!=c.at(i)){cout<<-1<<endl;return 0;}
    if(used.at(s.at(i)-1)==0)a+=pow(10,s.at(i)-1)*c.at(i);
    used.at(s.at(i)-1)=c.at(i);
    if(s.at(i)==1&&c.at(i)==0){cout<<-1<endl;return 0;}
  }
  cout<<a<<endl;
}