#include<bits/stdc++.h>
#include<algorithm>
#include<functional>
//#include<boost/multiprecision/cpp_int.hpp>
#define f(n) for(long long int i=0;i<n;i++)
#define g(n) for(long long int j=0;j<n;j++)
#define ff(a,n) for(long long int i=a;i<n;i++)
#define gg(a,n) for(long long int j=a;j<n;j++)
#define t(a) long long int a;cin>>a
#define test(te) t(te); while(te--)
#define all(a) a.begin(),a.end()
#define end "\n"
#define pri(a,n) f(n){cout<<a[i]<<" ";}cout<<end
#define pb push_back
#define mp make_pair
#define mod 1000000007  
#define ll long long 
#define lli long long int
#define op std::ios_base::sync_with_stdio(false);cin.tie(NULL)
//using namespace boost::multiprecision;
using namespace std;

int main(int argc, char const *argv[])
{
    op;
    t(n);
    t(m);
    lli arr[n]={0};
    bool flag=true;
    f(m)
    {
    	t(a);
    	t(b);
    	if(arr[a-1]==0 || arr[a-1]==b)
    		arr[a-1]=b;
    	else 
    	{
    		flag=false;
    		break;
    	}
    }
    lli sum=0;
    f(n)
    {
    	sum+=arr[i];
    }
    if(sum==0)
    	flag=false;

    if(flag)
    {
    	f(n)
    		cout<<arr[i];
    }
    else
    	cout<<"-1\n";
    return 0;
}
