#include <bits/stdc++.h>
using namespace std;
int s[100], c[100];
int main() {
  int m, n, i, j, k;
  cin >> m >> n;
  int a[m];
  memset(a, -1, sizeof(a));
  for (i = 1; i <= n; i++) cin >> s[i] >> c[i];
  for (i = 1; i <= n - 1; i++)
    for (j = i + 1; j <= n; j++)
      if (s[i] == s[j] && c[i] != c[j]) {
        cout << -1;
        return 0;
      }
  for (i = 0; i < m; i++) {
    for (j = 1; j <= n; j++)
      if (s[j] == i + 1) {
        for (k = 1; k <= n; k++)
          if (s[k] == s[j]) a[i] = c[k];
      }
  }
  if (a[0] == 0) {
    a[0] = 1;
    for (i = 1; i < m; i++)
      if (a[i] == -1) a[i] = 0;
    for (i = 0; i < m; i++) cout << a[i];
  } else {
    for (i = 0; i < m; i++)
      if (a[i] == -1) a[i] = 0;
    for (i = 0; i < m; i++) cout << a[i];
  }
  return 0;
}
