#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  map<int, int> mp;
  for (int i = 0; i < n; i++) {
    mp[i] = -1;
  }
  bool flag = true;
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    if (mp[s - 1] == -1)
      mp[s - 1] = c;
    else {
      if (mp[s - 1] == c)
        continue;
      else {
        flag = false;
        break;
      }
    }
  }
  if (mp[0] == 0) flag = false;
  for (int i = 0; i < n; i++) {
    if (i != 0 && mp[i] == -1) mp[i] = 0;
    if (i == 0 && mp[i] == -1) mp[i] = 1;
  }
  if (flag) {
    for (int i = 0; i < n; i++) {
      if (i != n - 1)
        printf("%d", mp[i]);
      else
        printf("%d\n", mp[i]);
    }
  } else
    printf("-1\n");
  return 0;
}
