#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  if (n == 1) {
    if (!m) {
      cout << "0\n";
    } else if (m == 1) {
      int s, c;
      cin >> s >> c;
      cout << c << "\n";
    } else {
      int s, c;
      cin >> s >> c;
      bool f = true;
      for (long long i = (1); i < (m - 1); i++) {
        int s1, c1;
        cin >> s1 >> c1;
        if (c1 != c) f = false;
      }
      if (f)
        cout << c << "\n";
      else
        cout << "-1\n";
    }
  } else {
    char num[n];
    bool f = true;
    for (long long i = (0); i < (n); i++) num[i] = -1;
    for (long long i = (0); i < (m); i++) {
      int s, c;
      cin >> s >> c;
      s--;
      if (s == 0 && c == 0) {
        f = false;
        break;
      } else {
        if (num[s] == -1)
          num[s] = c;
        else if (num[s] != c) {
          f = false;
          break;
        }
      }
    }
    if (f) {
      if (num[0] == -1)
        printf("1");
      else {
        printf("%d", num[0]);
      }
      for (long long i = (1); i < (n); i++) {
        if (num[i] == -1)
          printf("0");
        else
          printf("%d", num[i]);
      }
      puts("");
    } else {
      printf("-1\n");
    }
  }
}
