#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  while (t--) {
    int n, m;
    cin >> n >> m;
    int s, c;
    int A[3];
    A[0] = -1;
    A[1] = -1;
    A[2] = -1;
    bool flag = true;
    for (int i = 0; i < m; i++) {
      cin >> s >> c;
      if (A[s - 1] == -1 || A[s - 1] == c)
        A[s - 1] = c;
      else
        flag = false;
    }
    if (A[0] == 0) flag = false;
    if (flag) {
      for (int i = 0; i < n; i++) {
        if (A[i] == -1) A[i] = 0;
      }
      if (n > 1) {
        if (A[0] == 0) A[0] = 1;
      }
      for (int i = 0; i < n; i++) cout << A[i];
    } else
      cout << "-1";
  }
  return 0;
}
