#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long ncr(long long n, long long r) {
  long long i, ans = 1, k = 0;
  if (r == 0)
    return 1;
  else if (n < r)
    return 0;
  for (i = n; i >= n - r + 1; i--) {
    ans *= i;
    ans /= n - i + 1;
  }
  return ans;
}
bool visited[6] = {false};
int n = 6;
vector<int> adj[6];
void max_heapify(int a[100], int i) {
  int l, r, largest = i;
  l = 2 * i + 1;
  r = 2 * i + 2;
  if (l < n && a[l] > a[i]) largest = l;
  if (r < n && a[r] > a[l]) largest = r;
  if (largest != i) {
    int k;
    k = a[i];
    a[i] = a[largest];
    a[largest] = k;
    max_heapify(a, largest);
  }
}
int power(long long x, long long y, long long p) {
  int res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
bool square(long long n) {
  double x;
  x = sqrt(n);
  if (x == floor(x))
    return true;
  else
    return false;
}
bool prime(long long n) {
  long long i;
  for (i = 2; i * i <= n; i++) {
    if (n % i == 0) return false;
  }
  return true;
}
long long arr[1000];
void dfs(long long a, vector<long long> adj[100099], bool visited[100001],
         long long& count, vector<long long> in, long long n, long long ans[]) {
  visited[a] = true;
  if (a <= n) {
    count++;
    arr[count - 1] = a;
  }
  for (auto u : adj[a]) {
    if (!visited[u]) {
      visited[u] = true;
      dfs(u, adj, visited, count, in, n, ans);
    }
  }
  for (long long i = 0; i < count; i++) {
    ans[arr[i]] = count;
  }
}
long long modi(long long a, long long m) { return power(a, m - 2, m); }
long long calhash(string& s) {
  long long i, hash = 0, p = 1, pow = 3;
  for (i = 0; s[i] != '\0'; i++) {
    hash = (hash + p * (s[i] - 'a' + 1)) % 1000000007;
    p *= pow;
  }
  return hash;
}
long long digit(long long n) {
  long long count = 0;
  while (n != 0) {
    n = n / 10;
    ++count;
  }
  return count;
}
int main() {
  long long arr[3], n, m, i, s, c;
  arr[0] = -1, arr[1] = -1, arr[2] = -1;
  cin >> n >> m;
  bool ans = true;
  for (i = 0; i < m; i++) {
    cin >> s >> c;
    if (arr[s - 1] < 0) {
      arr[s - 1] = c;
    } else {
      if (arr[s - 1] != c) {
        ans = false;
      }
    }
  }
  if (ans) {
    i = n - 1;
    while (arr[i] < 0) {
      i--;
    }
    long long j;
    for (j = 0; j <= i; j++) {
      if (arr[j] < 0) {
        arr[j] = 0;
      }
    }
    long long num = 0;
    for (j = 0; j <= i; j++) {
      num += pow(10, i - j) * arr[j];
    }
    if (digit(num) == n) {
      cout << num;
      return 0;
    } else
      cout << -1;
  } else
    cout << "-1";
  return 0;
}
