#include <bits/stdc++.h>
using namespace std;
int a[100050], s[10005], c[10005];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> s[i] >> c[i];
  }
  int flag = 1;
  for (int i = 1; i < m; i++) {
    if (s[i] == 1 && c[i] == 0 && n > 1) {
      flag = 0;
      break;
    }
    for (int j = i + 1; j <= m; j++) {
      if (s[i] == s[j] && c[i] != c[j]) {
        flag = 0;
        break;
      }
    }
    if (!flag) break;
  }
  if (!flag)
    cout << "-1\n";
  else {
    for (int i = 1; i <= m; i++) {
      a[s[i]] = c[i];
    }
    if (a[1] == 0) a[1] = 1;
    for (int i = 1; i <= n; i++) cout << a[i];
    cout << '\n';
  }
  return 0;
}
