#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000 + 5;
const int inf = 0x3f3f3f3f;
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m, s, c;
  cin >> n >> m;
  int f = 1;
  int nums[5] = {0};
  int flag[5] = {0};
  while (m--) {
    cin >> s >> c;
    if (s > n)
      f = 0;
    else {
      if (n != 1 && s == 1 && c == 0) f = 0;
      if (nums[s] == c) {
        flag[s] = 1;
        continue;
      }
      if (flag[s] == 1) f = 0;
      nums[s] = c;
      flag[s] = 1;
    }
  }
  if (f) {
    for (int i = 1; i <= n; i++) {
      cout << nums[i];
    }
  } else {
    cout << -1;
  }
  return 0;
}
