#include <bits/stdc++.h>
#include <math.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;


int main() {
int n,m;
cin >> n >> m;
int s;
char c;
char ans[n]={0};

int check[n];
bool flg = true;
REP(i,m) {
  cin >> s >> c;
  if(check[s-1]!=0&&ans[s-1]!=c) flg = false;
  check[s-1]++;
  ans[s-1] = c;
}
if(flg==true&&ans[0]==0) {
  ans[0]=1;
  cout << ans << endl;
} else {
  cout << "-1" << endl;
}
return 0;
}
