#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int maxn = 110000;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setiosflags(ios::fixed) << setprecision(12);
  int n, m;
  cin >> n >> m;
  vector<int> a(n + 1, -1);
  int s[10], c[10];
  for (int i = 1; i <= m; i++) {
    cin >> s[i] >> c[i];
  }
  int flag = 0;
  if (n == 1) {
    for (int i = 1; i <= m; i++) {
      if (a[s[i]] == -1) {
        a[s[i]] = c[i];
      } else {
        if (a[s[i]] != c[i]) {
          flag = 1;
          break;
        }
      }
    }
    if (!flag)
      cout << a[1];
    else
      cout << -1 << "\n";
  } else {
    for (int i = 1; i <= m; i++) {
      if (a[s[i]] == -1) {
        if (s[i] == 1 && c[i] == 0) {
          flag = 1;
          break;
        }
        a[s[i]] = c[i];
      } else {
        if (a[s[i]] != c[i]) {
          flag = 1;
          break;
        }
      }
    }
    if (flag)
      cout << -1 << "\n";
    else {
      for (int i = 1; i <= n; i++) {
        if (i == 1 && a[i] == -1)
          cout << 1;
        else if (i > 1 && a[i] == -1)
          cout << 0;
        else
          cout << a[i];
      }
      cout << "\n";
    }
  }
  return 0;
}
