/*****************/
/*

Sharma Ji Ka Ladka
MNNIT Allahabad

*/
/*****************/

#include<bits/stdc++.h>
using namespace std;

#define For(i,a,b)                              for (int i=a;i<b;i++)
#define Forl(i,size)                            for (int i=0;i<size;i++)
#define Forr(i,size)                            for (int i=size-1;i>=0;i--)
#define ForR(i,a,b)                             for(int i=a;i>=b;i--)
#define s(n)                                    scanf("%d",&n)
#define p(n)                                    printf("%d\n",n)
#define ps(n)                                   printf("%s\n",n)
#define sd(n)                                   int n;scanf("%d",&n)
#define sl(n)                                   long long int n;scanf("%lld",&n)
#define pb(n)                                   push_back(n)
#define clr(a)                                  memset(a,0,sizeof(a))
#define all(c)                                  (c).begin(),(c).end()
#define len                                     length()
#define size                                     size()
#define mp(a,b)                                 make_pair(a,b)
#define fi first
#define se second
typedef __int64 ull;
#define ret return 0;
#define PI 3.14159265
#define snuke(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);   
const long long Mod =1e9+7; 
// string a,b,s,c,d;

typedef vector <int> vi;
typedef vector <vi> vvi;
typedef vector <string> vst;
typedef vector <bool> vb;
typedef pair<int,int> pii;
typedef long long ll;
ll sum=0,ans=0,res=0;
int i, j, k;



bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ if(a.se==b.se)
    return (a.fi < b.fi);

    return (a.se < b.se); 
}

// IS PRIME FUNCTION STARTS   

bool isPrime(ll num){
    bool flag=true;
    if(num==1)return false;
    for(int i = 2; i <= sqrt(num); i++) {
       if(num % i == 0) {
          flag = false;
          break;
       }
    }
    return flag;
}

//IS PRIME FUNCTION ENDS


//**Array Sum Function**

ll findSum(ll a[],int l,int r)
{ll sum=0;
    For(i,l,r)
    {
        sum+=a[i];
    }
    return sum;
}

//**Array Sum Function Ends**


//Prime Factors Of A Number 

vector<pair<int,int>> vec1; //Prime Factors along with their exponents
void primeFactors(ll n) 
{ int c1=0;
	// Print the number of 2s that divide n 
	while (n%2 == 0) 
	{ 
		// printf("%d ", 2); 
		n = n/2;c1++; 
	} if(c1)
    vec1.pb(mp(2,c1));
c1=0;
	// n must be odd at this point. So we can skip 
	// one element (Note i = i +2) 
	for (int i = 3; i <= sqrt(n); i = i+2) 
	{ c1=0;
		// While i divides n, print i and divide n 
		while (n%i == 0) 
		{ 
			// printf("%d ", i); 
		    
            n = n/i;c1++; 
		} 
        if(c1)
        vec1.pb(mp(i,c1));
	} 
c1=0;
	// This condition is to handle the case when n 
	// is a prime number greater than 2 
	if (n > 2) 
	vec1.pb(mp(n,1));
} 

//Ends



//*** Power Function Starts
ll power(int x, unsigned int y) 
{ 
    int temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2); 
    if (y%2 == 0) 
        return temp*temp; 
    else
        return x*temp*temp; 
} 
//*** Power function ends 

//nCr function starts

ull nCr(ll n,ll r)
{
ull p=1;ull k=1;
if(n-r<r)
r=n-r;

if(r!=0)
{
    while(r)
    {
        p*=n;k*=r;
        ll m=__gcd(p,k);
        p/=m;k/=m;     //Simplifying 
        n--;r--;
    }

}
else p=1;

return p;


}


//nCr function ends


// ** LCM of two numbers
ll lcm(ll a, ll b){
    return a / __gcd(a, b) * b;
}
//** Ends //


//** Count Set Bits Functon

unsigned int countBits(ll n,int specify) 
{ 
    unsigned int count = 0,total=0; 
    if (n==0){if(specify == 1)return 0;else return 1;}
    while (n) { 
        total+=1;
        count += n & 1; 
        n >>= 1; 
    } 
    if(specify==1)
    return count; 
    else return (total-count);
}

//** Ends //


//Array Scanner starts

void scar(ll a[],int n)
{
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
}

//Array Scanner ends



signed main() {
    // boost
string aux1,aux2,aux3;

    int T = 1;
    // cin>>T;
    Forl(ZA,T)
    {int f=0,fl1=0,fl2=0,c1=0,c2=0,cont=0,cnt=0,c3=0,auxi=0,auxj=0;
    ll mi=INT_MAX;ll ma=INT_MIN,sol=0;
  
    sd(n);sd(m);
    vector<int>vec[10];
    For(i,0,m)
    {
        cin>>c1>>c2;
        if(vec[c1].size==0)
        {
            vec[c1].pb(c2);
        }
        else
        {
            auto it=find(vec[c1].begin(),vec[c1].end(),c2);
            if(it==vec[c1].end())
            {cout<<"-1\n";ret}
            
            
        }
        
    }
    if(vec[1].size!=0&&vec[1][0]==0&&n!=1){cout<<"-1\n";ret}
    else if(vec[1].size!=0&&vec[1][0]==0&&n==1){cout<<"0\n";ret}
    else if(vec[1].size!=0&&vec[1][0]!=0){cout<<vec[1][0];}
    else if(vec[1].size==0){cout<<"9";}
    for(int i=2;i<=n;i++)
    {
        if(vec[i].size!=0)
        {
                        cout<<vec[i][0];
        } 
        else if(vec[i].size==0)
        {
            cout<<0;
        }
    
    }
    cout<<endl;
    
    }
    return 0;
}

