#define _GLIBCXX_DEBUG
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<string>
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rep2(i,s,n) for(int i=s;i< (int)n; i++)
#define ll long long 
#define all(v) v.begin(),v.end()
using namespace std;
int main(){
  int n,m; cin >>n>>m;
  vector<int> a(m),b(m);
  rep(i,m) cin >>a[i]>>b[i];
  vector<vector<int>> c(n);
  rep(i,m) c[a[i]-1].push_back(b[i]);
  if(c[0].size()==0||c[0]==0) c[0].push_back(1);
  rep2(i,1,n) if(c[i].size()==0) c[i].push_back(0);
  int key=0;
  rep(i,n) rep(j,c[i].size()) if(c[i][j]!=c[i][0]) key=1;
  if(key==1) cout <<-1<<endl;
  else if(n==3) cout<<100*c[0][0]+10*c[1][0]+c[2][0]<<endl;
  else if(n==2) cout<<10*c[0][0]+c[1][0]<<endl;
  else cout <<c[0][0]<<endl;
}
  