import std.stdio,std.math,std.string,std.conv,std.typecons,std.format;
import std.algorithm,std.range,std.array,std.numeric;

T[] readarr(T=long)(){return readln.chomp.split.to!(T[]);}
void scan(T...)(ref T args){auto input=readln.chomp.split;foreach(i,t;T)args[i]=input[i].to!t;}
struct Queue(T){T[]e;auto enq(T t){e~=t;}auto enq(T[]ts){e~=ts;}T deq(){T tp=e[0];e=e.length>1?e[1..$]:[];return tp;}}
struct Stack(T){T[]e;auto push(T t){e~=t;}auto push(T[]ts){e~=ts;}T pop(){T tp=e[$-1];e=e.length>1?e[0..$-1]:[];return tp;}}

//END OF TEMPLATE

void main(){
    ulong n,m;
    scan(n,m);
    auto s=new ulong[m];
    auto c=new char[m];
    m.iota.each!(i=>scan(s[i],c[i]));
    s[]-=1;
    char[] str;
    str.length=n;
    str[]=' ';
    foreach(j,i;s){
        if(str[i]!=' '&&str[i]!=c[j]){
            "-1".writeln;
            return;
        }
        str[i]=c[j];
    }
    if(str.length!=1&&str[0]=='0'){
        "-1".writeln;
        return;
    }
    str.length.iota.each!(i=>str[i]=str[i]!=' '?str[i]:(i==0?'1':'0'));
    str.writeln;
}
