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