#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int a[5], b[5];
  int x, y;
  memset(b, 0, sizeof(b));
  memset(a, 0, sizeof(a));
  int flag = 1;
  while (m--) {
    cin >> x >> y;
    if (b[x] != 0 && (a[x] != y)) {
      flag = 0;
    }
    b[x] = 1;
    a[x] = y;
  }
  if (flag == 0) {
    cout << "-1" << endl;
    return 0;
  }
  if (n == 1)
    cout << y << endl;
  else {
    if (a[1] == 0 && b[1] != 0) {
      cout << "-1" << endl;
      return 0;
    }
    if (a[1] == 0 && b[1] == 0) {
      cout << 1;
      for (int i = 2; i <= n; ++i) {
        if (a[i] != 0)
          cout << a[i];
        else
          cout << 0;
      }
      cout << endl;
      return 0;
    }
    for (int i = 1; i <= n; ++i) {
      if (a[i] != 0)
        cout << a[i];
      else
        cout << 0;
    }
    cout << endl;
  }
  return 0;
}
