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