#include <bits/stdc++.h>
using namespace std;
double na, nb;
string s;
int x[5];
int vis[5];
int n, m;
int main() {
  cin >> n >> m;
  int flag = 1;
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    if ((n > 1 && s == 1 && c == 0) || (vis[s] && x[s] != c))
      flag = 0;
    else {
      x[s] = c;
      vis[s] = 1;
    }
  }
  if (flag == 0)
    cout << -1 << endl;
  else {
    for (int i = 1; i <= n; i++) {
      if (i == 1 && x[i] == 0)
        cout << 1;
      else
        cout << x[i];
    }
    cout << endl;
  }
  return 0;
}
