#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, s, c, a[10];
  map<int, int> m;
  cin >> N >> M;
  int flag = 1;
  while (M--) {
    cin >> s >> c;
    if (m.count(s) == 0) {
      m[s] = c;
      a[s] = c;
    } else {
      if (m[s] != c) flag = 0;
    }
  }
  if (a[1] == 0 && N > 1) flag = 0;
  if (flag == 0) {
    cout << -1 << endl;
    return 0;
  } else {
    if (N > 1) {
      for (int i = 1; i <= N; i++) {
        if (a[i] == -1 && i == 1)
          cout << 1;
        else if (a[i] == -1 && i > 1)
          cout << 0;
        else
          cout << a[i];
      }
    } else {
      if (a[1] == -1)
        cout << 0;
      else
        cout << a[1];
    }
    cout << endl;
  }
  return 0;
}
