#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
long long n, m, a[15], s, c, num[10], f = 1, len;
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) a[i] = -1;
  for (int i = 0; i <= 9; i++) num[i] = 0;
  len = pow(n, 10);
  n = 0;
  while (len > 0) {
    n++;
    len = len / 10;
  }
  for (int i = 1; i <= m; i++) {
    cin >> s >> c;
    if (a[s] == -1) {
      if (s == 1 && c == 0) f = 0;
      a[s] = c;
      num[c] = 1;
    } else {
      if (a[s] != c) f = 0;
    }
  }
  if (f == 0) {
    cout << "-1" << endl;
    return 0;
  } else if (n == 1 && a[1] == -1) {
    cout << "0" << endl;
    return 0;
  } else {
    for (int i = 1; i <= n; i++) {
      if (a[i] == -1) {
        if (i == 1) {
          for (int j = 1; j <= 9; j++) {
            if (num[j] == 0) {
              a[i] = j;
              num[j] = 1;
              break;
            }
          }
        } else {
          for (int j = 0; j <= 9; j++) {
            if (num[j] == 0) {
              a[i] = j;
              num[j] = 1;
              break;
            }
          }
        }
      }
    }
    for (int i = 1; i <= n; i++) cout << a[i];
    cout << endl;
  }
  return 0;
}
