//include,namespace
 #include<bits/stdc++.h>
 #include<iostream> 
 #include <queue>
 #include <vector>
 #include <string>
 using namespace std;
//REPmacro
 #define all(x) (x).begin(),(x).end()             //ソート
 #define FOR(i,x,n)for(int i=(x);i<(n);i++)
 #define FOR_R(i,x,n) for(int i=(n-1);i>=(x);i--)
 #define REP(i, n) FOR(i, 0, n)
 #define REP_R(i, n) FOR_R(i, 0, n)
//long long(define)
 using ll = long long;
 typedef long long ll;
 typedef long long int64;
 typedef long long lint;
 typedef long long lli;
////////////////いろいろあるよ//////////////////////////////////
 
int main(){
  	int N,M;
  	cin >> N >> M;
  	int data[N];
  	REP(i,N)data[i]=-1;
  	REP(i,M){
    	int A,B;
      	cin >> A;
      	cin >> B;
      	if(data[A-1]!=B && data[A-1]!=-1){
          cout << -1 << endl;
          return 0;
        }
      	data[A-1]=B;
    }
  	bool boolean=false;
  	if(N==0&&M==0){cout << 0 << endl;return 0}
  	REP(i,N){
    	if(boolean==false&&(data[i]!=-1 || data != 0)){
        	boolean = true;
          	int sum=0;
          	FOR(j,i,N){if(data[j]==-1)data[j]=0;sum+=data[j];}
          	if(sum==0){
              cout << -1 << endl;
              return 0;
            }
           cout << data[i];
        }else if(boolean==false){continue;
        }else{
          	
          	
        	cout << data[i];
        }
    }
  cout << endl;
}
